{"id":23478,"date":"2018-12-15T11:00:31","date_gmt":"2018-12-15T11:00:31","guid":{"rendered":"https:\/\/getflywheel.com\/?p=23478"},"modified":"2025-04-25T08:52:30","modified_gmt":"2025-04-25T13:52:30","slug":"combine-flexbox-and-css-grids-for-layouts-how-to","status":"publish","type":"resource","link":"https:\/\/wpengine.com\/case-studies\/resources\/combine-flexbox-and-css-grids-for-layouts-how-to\/","title":{"rendered":"How To Combine Flexbox and CSS Grids for Efficient Layouts"},"content":{"rendered":"\n<p><em>Editor&#8217;s note: This guest post was written by <a data-type=\"URL\" data-id=\"https:\/\/abbeyjfitzgerald.com\/\" href=\"https:\/\/abbeyjfitzgerald.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Abbey Fitzgerald<\/a> a UX software engineer and web designer who loves the art of crafting code.<\/em><\/p>\n\n\n\n<p>In the past, CSS float properties were one of the main methods for arranging elements on a website. And if you\u2019ve ever worked that way, you know that it\u2019s not always ideal for complex layouts. Luckily in the modern era of web design, aligning elements has become much more streamlined thanks to Flexbox and CSS Grids.<\/p>\n\n\n\n<p>When Flexbox came along, it made alignment much easier and has since been widely adopted. <a href=\"https:\/\/wpengine.com\/resources\/css-grid-layouts-how-to\/\" target=\"_blank\" rel=\"noreferrer noopener\">CSS Grid Layouts<\/a> have also created a lot of excitement in the web design community. A while back, we took a look at how to create a basic <a href=\"https:\/\/wpengine.com\/resources\/css-grid-layouts-how-to\/\" target=\"_blank\" rel=\"noreferrer noopener\">CSS Grid Layout<\/a>. Although it is not widely adopted, browsers are starting to adopt support for it. When it is fully supported, this will have a great impact on designs. Browser support is increasing all the time; be sure to check out <a href=\"http:\/\/caniuse.com\/#search=css%20grid%20layout\" target=\"_blank\" rel=\"noopener noreferrer\">Can I Use<\/a> for the most up-to-date information.<\/p>\n\n\n\n<p>Now you may be wondering what\u2019s next; after all, Flexbox and CSS Grid Layouts seem to accomplish similar results. It\u2019s not a Flexbox versus Grid debate, however, but more of learning how to use them together. The more I\u2019ve played around with both Grid and Flexbox, I\u2019ve found that you don\u2019t have to choose just one or the other. In the near future, when CSS Grid Layouts have full browser support, designers will be able to take the combined advantages of each and create the most efficient and interesting designs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Testing Basic Flexbox and CSS Grid Layouts<\/h2>\n\n\n\n<p>In order to determine if Flexbox or CSS Grid works better for your development workflow, creating a standard layout that only uses one or the other is a good way to see how they work and if there are advantages of one over the another. We\u2019ll start with a &nbsp;very simple and very familiar layout type with a header, sidebar, main content, and footer. A simple layout like this is a quick way to get the various elements positioned.<\/p>\n\n\n\n<p>And remember, you should never make changes on your live site. Try experimenting with <a href=\"https:\/\/wpengine.com\/local\/\" target=\"_blank\" rel=\"noreferrer noopener\">Local <\/a>instead, a free local WordPress development app. Download it today!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How To Create a Layout With Flexbox<\/h2>\n\n\n\n<p>Recently, I covered the subject of creating a Flexbox card layout. That post goes into detail about how Flexbox works along with specific CSS information, so if you\u2019re a beginner to Flexbox, it will help you get familiar with how it works.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2017\/08\/flexbox-layout.jpg\" alt=\"Screenshot of CSS Grid and Flexbox Design Layout\" class=\"wp-image-23752\"\/><\/figure>\n\n\n\n<p>For this tutorial, here\u2019s what we\u2019ll be building:<br><\/p>\n\n\n\n<p>See this on <a href=\"https:\/\/codepen.io\/abbeyjfitzgerald\/pen\/jwqrZY\" target=\"_blank\" rel=\"noopener noreferrer\">Codepen<\/a>.<\/p>\n\n\n\n<p>For this basic layout, the main Flexbox tasks include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create full width header and footer<\/li>\n\n\n\n<li>Position sidebar next to main content area<\/li>\n\n\n\n<li>Correct sizing of sidebar and main content area<\/li>\n\n\n\n<li>Navigation elements positioning<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Basic HTML structure<\/h3>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;div class=\"container\"&gt;\n        \n    &lt;header&gt;\n        &lt;nav&gt;\n          &lt;ul&gt;\n            &lt;li&gt;&lt;\/li&gt;\n            &lt;li&gt;&lt;\/li&gt;\n            &lt;li&gt;&lt;\/li&gt;\n          &lt;\/ul&gt;\n        &lt;\/nav&gt;\n        &lt;button&gt;&lt;\/button&gt;\n    &lt;\/header&gt;\n    &lt;div class=\"wrapper\"&gt;\n        &lt;aside class=\"sidebar\"&gt;\n            &lt;h3&gt;&lt;\/h3&gt;\n        &lt;\/aside&gt;\n        &lt;section class=\"main\"&gt;\n            &lt;h2&gt;&lt;\/h2&gt;\n            &lt;p&gt;&lt;\/p&gt;\n        &lt;\/section&gt;\n    &lt;\/div&gt;&lt;!-- \/wrapper --&gt;\n    &lt;footer&gt;\n        &lt;h3&gt;&lt;\/h3&gt;\n        &lt;p&gt;&lt;\/p&gt;\n    &lt;\/footer&gt;\n&lt;\/div&gt;&lt;! -- \/container --&gt;\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">How to use flex display<\/h3>\n\n\n\n<p><strong>Header styling<\/strong><\/p>\n\n\n\n<p>Starting from the outside and working in, adding <code>display: flex;<\/code> to the container is the first step in any Flexbox layout. The flex-direction is set to column, so this will position all sections under each other.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">.container {\n    display: flex;\n    flex-direction: column;\n}<\/pre>\n\n\n\n<p>Creating a full-width header was pretty automatic with the <code>display: flex;<\/code> (headers are a block level element by default). Because of this declaration, it will allow for easy placement for navigation elements.<\/p>\n\n\n\n<p>There is a logo and two menu items in the navigation on the left with a login button on the right. The nav is in the header, so by having <code>justify-content: space-between;<\/code> the navigation and button will be spaced automatically.<\/p>\n\n\n\n<p>One handy thing is how easy it is to align text. In the navigation, with <code>align-items: baseline;<\/code>, all navigation items are aligned to the baseline of the text so they look more uniform.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2017\/08\/flexbox-justify-content.jpg\" alt=\"CSS Grid and Flexbox Justify Content Visualization\" class=\"wp-image-23753\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">header{\n    padding: 15px;\n    margin-bottom: 40px;\n    display: flex;\n    justify-content: space-between;\n}\nheader nav ul {\n    display: flex;\n    align-items: baseline;\n    list-style-type: none;\n}<\/pre>\n\n\n\n<p><strong>Page content styling<\/strong><\/p>\n\n\n\n<p>Next, there is the sidebar and main content areas with a wrapper that includes the two. The div with a class of <code>.wrapper<\/code> also needs the <code>display: flex;<\/code> but the flex-direction is different than above. Because the sidebar and content areas are next to each other rather than stacked, the flex-direction is<\/p>\n\n\n\n<p>Next, there is the sidebar and main content areas with a wrapper that includes the two. The div with a class of .wrapper also needs the display: flex; but the flex-direction is different than above. Because the sidebar and content areas are next to each other rather than stacked, the flex-direction is row, which is the opposite of what was done in the container above.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">.wrapper {\n    display: flex;\n    flex-direction: row;\n}<\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2017\/08\/flexbox-content-areas.jpg\" alt=\"CSS Grid with Flexbox - Detailed Screenshot of Content Areas\" class=\"wp-image-23754\"\/><\/figure>\n\n\n\n<p>The size of the main section and the sidebar is very important since more prominent information lives here. The main content should be three times the size of the sidebar, which is pretty easy to do with Flexbox.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">.main {\n    flex: 3;\n    margin-right: 60px;\n}\n.sidebar {\n   flex: 1;\n}<\/pre>\n\n\n\n<p>For this code snippet, I used shorthand. The flex values are for the flex-grow property. Flex-grow is powerful because this is how much the item(s) will grow relative to the rest of the flexible items inside the same container.<\/p>\n\n\n\n<p>Overall, Flexbox was pretty efficient in creating this simple layout. It was especially helpful having control over the styling of list items and spacing between the navigation and the button.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How To Create a Layout With CSS Grid Layouts<\/h2>\n\n\n\n<p>To test efficiency, the next step is to build the same basic layout with CSS Grid. The page elements are all the same and will be positioned the same way as the Flexbox example.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2017\/08\/css-grid-layout.jpg\" alt=\"SEO Optimized CSS Grid Flexbox Layout Screenshot\" class=\"wp-image-23755\"\/><\/figure>\n\n\n\n<p>See this on <a href=\"https:\/\/codepen.io\/abbeyjfitzgerald\/pen\/qjZNpz\" target=\"_blank\" rel=\"noopener noreferrer\">Codepen<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Grid Template Areas<\/h3>\n\n\n\n<p>One handy thing with CSS Grid is the ability to specify template areas, which can make defining layouts very intuitive. By taking this approach, areas on the grid can be named and referenced to position items. For this basic layout, there are four items we\u2019ll need to name:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>header<\/li>\n\n\n\n<li>main content<\/li>\n\n\n\n<li>sidebar<\/li>\n\n\n\n<li>footer<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Basic HTML Structure<\/h3>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;div class=\"container\"&gt;\n        \n    &lt;header&gt;\n        &lt;nav&gt;\n          &lt;ul&gt;\n            &lt;li&gt;&lt;\/li&gt;\n            &lt;li&gt;&lt;\/li&gt;\n            &lt;li&gt;&lt;\/li&gt;\n          &lt;\/ul&gt;\n        &lt;\/nav&gt;\n        &lt;button&gt;&lt;\/button&gt;\n    &lt;\/header&gt;\n  \n    &lt;aside class=\"sidebar\"&gt;\n        &lt;h3&gt;&lt;\/h3&gt;\n        &lt;ul&gt;\n            &lt;li&gt;&lt;\/li&gt;\n        \t&lt;li&gt;&lt;\/li&gt;\n\t&lt;li&gt;&lt;\/li&gt;\n\t&lt;li&gt;&lt;\/li&gt;\n\t&lt;li&gt;&lt;\/li&gt;\n          &lt;\/ul&gt;\n    &lt;\/aside&gt;\n    &lt;section class=\"main\"&gt;\n        &lt;h2&gt;&lt;\/h2&gt;\n        &lt;p&gt;&lt;\/p&gt;\n         &lt;p&gt; &lt;\/p&gt;\n  &lt;\/section&gt;\n    &lt;footer&gt;\n        &lt;h3&gt;&lt;\/h3&gt;\n        &lt;p&gt;&lt;\/p&gt;\n    &lt;\/footer&gt;\n&lt;\/div&gt;\n<\/pre>\n\n\n\n<p>We\u2019ll define these areas on our grid container in order, kind of like drawing them out. I\u2019ll also space them out for readability.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">grid-template-areas:\n        \"header header\"\n        \"sidebar main\"\n        \"footer footer\";<\/pre>\n\n\n\n<p>Note how the sidebar was listed before main? Switching them around would also make the order change on the page. Currently, the sidebar is on the left and the main content is on the right, but you could easily change it if needed.<\/p>\n\n\n\n<p>One thing to note: These names need to be \u201cconnected\u201d to the styling. Just because grid-template-areas have been declared, we don\u2019t know where the header actually belongs. In the header block, <code>grid-area: header;<\/code> needs to be added.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">header{\n    grid-area: header;\n    padding: 20px 0;\n    display: grid;\n    grid-template-columns: 1fr 1fr;\n}<\/pre>\n\n\n\n<p>The HTML structure is the same as it is in the Flexbox example, but the CSS is quite different to create the grid layout.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">.container{\n    max-width: 900px;\n    background-color: #fff;\n    margin: 0 auto;\n    padding: 0 60px;\n    display: grid;\n    grid-template-columns: 1fr 3fr;\n    grid-template-areas:\n        \"header header\"\n        \"sidebar main\"\n        \"footer footer\";\n    grid-gap: 50px;\n}<\/pre>\n\n\n\n<p>To begin working with a CSS Grid Layout, it is very important to have <code>display: grid;<\/code> set on the container. The grid-template-columns are declared here to give the overall structure of the page. Remember how the Flexbox example had the <code>.main<\/code> class set to a flex-grow of 3 and the sidebar had a flex-grow of 1 to establish sizing? Here the grid-template-columns have been set as 1fr and 3fr. This is where the grid is taking shape with the fractional units. With these values, it is apparent there are two columns and they are not equal width. The column set to 3fr is three times wider than the other. This explains how the sidebar appears more narrow than the content area.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2017\/08\/basic-column-for-grid.jpg\" alt=\"Essential CSS Grid with Flexbox - Fundamental Column Grid Screenshot\" class=\"wp-image-23756\"\/><\/figure>\n\n\n\n<p>Next, the fr units used for the container need to be adjusted for the header. The grid-template-columns have been adjusted to 1fr and 1fr. That way there are two equally sized columns and the navigation items and button will fit.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">header{\n    grid-area: header;\n    display: grid;\n    grid-template-columns: 1fr 1fr;\n}<\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2017\/08\/grid-header.jpg\" alt=\"CSS Grid and Flexbox Layouts - Detailed Screenshot of Grid Header\" class=\"wp-image-23774\"\/><\/figure>\n\n\n\n<p>To place the button, we just need to use justify-self and set it to end.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">header button {\n    justify-self: end;\n}<\/pre>\n\n\n\n<p>The navigation is placed where it needs to be:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">header nav {\n    justify-self: start;\n}<\/pre>\n\n\n\n<p>The full-width footer does not need different columns set since the content is in the middle.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How To Create a Layout With Both Flexbox and CSS Grids<\/h2>\n\n\n\n<p>Now that we\u2019ve seen what each method can do individually, it is time to create something more complex by combining Flexbox and CSS Grid Layouts.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2017\/08\/combined-layout.jpg\" alt=\"Optimized CSS Grid Layout Using Flexbox Techniques\" class=\"wp-image-23757\"\/><\/figure>\n\n\n\n<p>See this on <a href=\"https:\/\/codepen.io\/abbeyjfitzgerald\/pen\/RgRoKy\" target=\"_blank\" rel=\"noopener noreferrer\">Codepen<\/a>.<\/p>\n\n\n\n<p>Here is the basic outline for getting the grid going:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2017\/08\/combined-starter.jpg\" alt=\"Optimized CSS Grid Flexbox Design with Advanced Layout Techniques\" class=\"wp-image-23758\"\/><\/figure>\n\n\n\n<p>See this on <a href=\"https:\/\/codepen.io\/abbeyjfitzgerald\/pen\/zzqqYo\" target=\"_blank\" rel=\"noopener noreferrer\">Codepen<\/a>.<\/p>\n\n\n\n<p>Notice how the design relies on both columns and rows? This layout needs things to line up and behave consistently in both directions, so using CSS Grid is efficient for the overall layout.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2017\/08\/grid-sketch.jpg\" alt=\"Beginner's Guide to CSS Grid and Flexbox Combination\" class=\"wp-image-23759\"\/><\/figure>\n\n\n\n<p>Planning is key with a layout like this. It is a good idea to sketch it out first and see how things stack up, literally. To start the code, having display: grid; is essential; without it, using this type of layout will not work. One thing to note here is that there is spacing between the content blocks. This was achieved with grid-column-gap and grid-row-gap.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">.container {\n  display: grid;\n  grid-template-columns: 0.4fr 0.3fr 0.3fr;\n  grid-column-gap: 10px;\n  grid-row-gap: 15px;\n}<\/pre>\n\n\n\n<p>Fractional units are back for this layout and there are now three areas needed. The first value of 0.4fr is slightly wider than the second and third, which are both 0.3fr.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Column and Row Layout<\/h3>\n\n\n\n<p>This is where it\u2019s important to reference the diagram from the beginning. Starting at the top, this is how the header is placed. It spans all columns and one row.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">.header {\n  grid-column-start: 1;\n  grid-column-end: 4;\n  grid-row-start: 1;\n  grid-row-end: 2;\n  background-color: #d5c9e2;\n}<\/pre>\n\n\n\n<p>If you want to use shorthand, the start and end values are on the same line and a separated with a slash. It would look like this:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">.header {\n  grid-column: 1 \/ 4;\n  grid-row: 1 \/ 2;\n  background-color: #55d4eb;\n}<\/pre>\n\n\n\n<p>To place all the other items, the proper grid and column values just need to be added to the CSS. Rather than go through them here one by one, this example is on <a href=\"https:\/\/codepen.io\/abbeyjfitzgerald\/pen\/zzqqYo\" target=\"_blank\" rel=\"noopener noreferrer\">Codepen<\/a>.<\/p>\n\n\n\n<p>After the Grid Layout is built, fine-tuning the content is the next step.<\/p>\n\n\n\n<p><strong>Navigation<\/strong><\/p>\n\n\n\n<p>Flexbox is perfect for placing the header elements. The basic layout example touched on this with justify-content: space-between. The grid example needed to have justify-self: start; on the navigation and justify-self: end; for the button to place things, but Flexbox made spacing easier for the navigation.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">.header {\n  grid-column: 1 \/ 4;\n  grid-row: 1 \/ 2;\n  color: #9f9c9c;\n  text-transform: uppercase;\n  border-bottom: 2px solid #b0e0ea;\n  padding: 20px 0;\n  display: flex;\n  justify-content: space-between;\n  align-items: center;\n}<\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2017\/08\/combined-menu.jpg\" alt=\"layout by flywheel grid and flexbox combined menu screenshot\" class=\"wp-image-23760\"\/><\/figure>\n\n\n\n<p>This same format will be followed here. The logo, menu items, and button utilized Flexbox\u2019s justify-content for spacing.<\/p>\n\n\n\n<p><strong>Column content grid<\/strong><\/p>\n\n\n\n<p>For occasions that require elements to line up in one direction, meaning it is more \u201cone-dimensional,\u201d typically Flexbox is the better option. Also, Flexbox is good at dynamically scaling elements. Maybe you\u2019ve tried this in a row of boxes by adding <code>display:flex;<\/code> on a parent element and flex properties on the child elements. With that technique, there\u2019s a nice line formed and it\u2019s an efficient way to make sure all elements are the same height.<\/p>\n\n\n\n<p><strong>Row content with text and buttons<\/strong><\/p>\n\n\n\n<p>In the \u201cextra content\u201d section, three areas with text and buttons have been added. Flexbox makes it easy to keep the set width for three columns.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2017\/08\/combined-layout-extra-content.jpg\" alt=\"Advanced CSS Grid with Flexbox Layout Screenshot - Extra Content Display\" class=\"wp-image-23761\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">.extra {\n  grid-column: 2 \/ 4;\n  grid-row: 4 \/ 5;\n  padding: 1rem;\n  display: flex;\n  flex-wrap: wrap;\n  border: 1px solid #ececec;\n  justify-content: space-between;\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">One Flexbox Exception<\/h3>\n\n\n\n<p>Yes, I did say that Flexbox is better for one dimensional layouts, grids, or columns, but If you read the <a href=\"https:\/\/getflywheel.com\/layout\/how-to-use-flexbox-to-create-a-modern-card-design-layout\/\" target=\"_blank\" rel=\"noopener noreferrer\">How to use Flexbox to create a modern CSS card design layout post<\/a>, there was a \u201clast row\u201d Flexbox hack that was demonstrated to keep rows and columns balanced, even without an even number of cards.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2017\/08\/combined-image-grid.jpg\" alt=\"CSS Grid and Flexbox Combined: Optimized Visual Layout Image\" class=\"wp-image-23762\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">.related-images {\n  grid-column: 1 \/ 3;\n  grid-row: 5 \/ 6;\n  display: grid;\n  grid-template-columns: repeat(4,1fr);\n  grid-gap: 1rem;\n}\n.related-images .icon {\n    background-color: white;\n    flex: 1 1 150px;\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Design Approach Summary<\/h3>\n\n\n\n<p>Basically, the approach I took here was to utilize CSS Grid Layout for the overall layout (and anything that was not linear in design). Within the grid content areas, Flexbox was used to order and fine-tune the styling within the grid areas.<\/p>\n\n\n\n<p>Hopefully, these exercises gave you a better idea of how to build layouts with both CSS Grid Layouts and Flexbox. To further set your sites up for success, check out <a href=\"https:\/\/wpengine.com\/wordpress-hosting\/\" target=\"_blank\" rel=\"noreferrer noopener\">WP Engine&#8217;s hosting for WordPress<\/a> to find a plan that suits your needs!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Editor&#8217;s note: This guest post was written by Abbey Fitzgerald a UX software engineer and web designer who loves the art of crafting code. In the past, CSS float properties were one of the main methods for arranging elements on a website. And if you\u2019ve ever worked that way, you know that it\u2019s not always<span class=\"tile__ellipses\">&hellip;<\/span><span class=\"tile__ellipses--animated\"><\/span><\/p>\n","protected":false},"author":1,"featured_media":139900,"template":"","resource-topic":[1396,901],"resource-role":[895,1397,896,897],"resource-type":[916],"class_list":["post-23478","resource","type-resource","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How To Combine Flexbox and CSS Grids for Efficient Layouts<\/title>\n<meta name=\"description\" content=\"Master responsive design using CSS grid and flexbox. Create stunning, user-friendly site layouts effortlessly and efficiently!\" \/>\n<meta name=\"robots\" content=\"noindex, follow\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Combine Flexbox and CSS Grids for Efficient Layouts\" \/>\n<meta property=\"og:description\" content=\"Master responsive design using CSS grid and flexbox. Create stunning, user-friendly site layouts effortlessly and efficiently!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wpengine.com\/case-studies\/resources\/combine-flexbox-and-css-grids-for-layouts-how-to\/\" \/>\n<meta property=\"og:site_name\" content=\"WP Engine\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/wpengine\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-25T13:52:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/12\/CSS-code.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"500\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@wpengine\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/resources\/combine-flexbox-and-css-grids-for-layouts-how-to\/\",\"url\":\"https:\/\/wpengine.com\/case-studies\/resources\/combine-flexbox-and-css-grids-for-layouts-how-to\/\",\"name\":\"How To Combine Flexbox and CSS Grids for Efficient Layouts\",\"isPartOf\":{\"@id\":\"https:\/\/wpengine.com\/case-studies\/#website\"},\"datePublished\":\"2018-12-15T11:00:31+00:00\",\"dateModified\":\"2025-04-25T13:52:30+00:00\",\"description\":\"Master responsive design using CSS grid and flexbox. Create stunning, user-friendly site layouts effortlessly and efficiently!\",\"breadcrumb\":{\"@id\":\"https:\/\/wpengine.com\/case-studies\/resources\/combine-flexbox-and-css-grids-for-layouts-how-to\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/wpengine.com\/case-studies\/resources\/combine-flexbox-and-css-grids-for-layouts-how-to\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/resources\/combine-flexbox-and-css-grids-for-layouts-how-to\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/wpengine.com\/case-studies\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Resources\",\"item\":\"https:\/\/wpengine.com\/case-studies\/resources\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How To Combine Flexbox and CSS Grids for Efficient Layouts\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/#website\",\"url\":\"https:\/\/wpengine.com\/case-studies\/\",\"name\":\"WP Engine\",\"description\":\"Managed Hosting for WordPress\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/wpengine.com\/case-studies\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/f5301455463371a10d1fc290e9ad0085\",\"name\":\"WP Engine\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g\",\"caption\":\"WP Engine\"},\"sameAs\":[\"https:\/\/wpengine.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Combine Flexbox and CSS Grids for Efficient Layouts","description":"Master responsive design using CSS grid and flexbox. Create stunning, user-friendly site layouts effortlessly and efficiently!","robots":{"index":"noindex","follow":"follow"},"og_locale":"en_US","og_type":"article","og_title":"How To Combine Flexbox and CSS Grids for Efficient Layouts","og_description":"Master responsive design using CSS grid and flexbox. Create stunning, user-friendly site layouts effortlessly and efficiently!","og_url":"https:\/\/wpengine.com\/case-studies\/resources\/combine-flexbox-and-css-grids-for-layouts-how-to\/","og_site_name":"WP Engine","article_publisher":"https:\/\/www.facebook.com\/wpengine","article_modified_time":"2025-04-25T13:52:30+00:00","og_image":[{"width":1100,"height":500,"url":"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/12\/CSS-code.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_site":"@wpengine","twitter_misc":{"Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/wpengine.com\/case-studies\/resources\/combine-flexbox-and-css-grids-for-layouts-how-to\/","url":"https:\/\/wpengine.com\/case-studies\/resources\/combine-flexbox-and-css-grids-for-layouts-how-to\/","name":"How To Combine Flexbox and CSS Grids for Efficient Layouts","isPartOf":{"@id":"https:\/\/wpengine.com\/case-studies\/#website"},"datePublished":"2018-12-15T11:00:31+00:00","dateModified":"2025-04-25T13:52:30+00:00","description":"Master responsive design using CSS grid and flexbox. Create stunning, user-friendly site layouts effortlessly and efficiently!","breadcrumb":{"@id":"https:\/\/wpengine.com\/case-studies\/resources\/combine-flexbox-and-css-grids-for-layouts-how-to\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wpengine.com\/case-studies\/resources\/combine-flexbox-and-css-grids-for-layouts-how-to\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/wpengine.com\/case-studies\/resources\/combine-flexbox-and-css-grids-for-layouts-how-to\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wpengine.com\/case-studies\/"},{"@type":"ListItem","position":2,"name":"Resources","item":"https:\/\/wpengine.com\/case-studies\/resources\/"},{"@type":"ListItem","position":3,"name":"How To Combine Flexbox and CSS Grids for Efficient Layouts"}]},{"@type":"WebSite","@id":"https:\/\/wpengine.com\/case-studies\/#website","url":"https:\/\/wpengine.com\/case-studies\/","name":"WP Engine","description":"Managed Hosting for WordPress","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wpengine.com\/case-studies\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/f5301455463371a10d1fc290e9ad0085","name":"WP Engine","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g","caption":"WP Engine"},"sameAs":["https:\/\/wpengine.com"]}]}},"acf":[],"grid_image_url":"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/12\/CSS-code_343x245.png","media-type":{"term_id":916,"name":"Article","slug":"article"},"role":"<strong>Roles:<\/strong> Agency, Designer, Developer, Freelancer","topic":"<strong>Topics:<\/strong> Design, WordPress","_links":{"self":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource\/23478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource"}],"about":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/types\/resource"}],"author":[{"embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/users\/1"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/media\/139900"}],"wp:attachment":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/media?parent=23478"}],"wp:term":[{"taxonomy":"resource-topic","embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource-topic?post=23478"},{"taxonomy":"resource-role","embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource-role?post=23478"},{"taxonomy":"resource-type","embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource-type?post=23478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}