

Full definitions and descriptions of these properties are available in MDN’s flexbox documentation. This time, we need to set the display property to flex on the rows, and also specify the flex-flow property.

See the Pen Easy Responsive CSS Grid Layout, Version 4: Flexbox by SitePoint ( on CodePen. Let’s first look at the HTML: Īnd our CSS: /* grid */ The negative margin varies depending on the position of the grid block, and the margin in between grid blocks remains fixed. This method makes use of negative margins to create CSS grid blocks with a fixed margin in between each block. Note: I’ve included embedded demos for each but in order to see the full responsive nature of each technique, it’s best to view the CodePen demos at full screen by clicking on the “edit on CodePen” link at the top of each demo. A CodePen demo will be provided with each example, so you can fork and/or play with the CSS in the demos. I’m going to simplify these methods by using minimal amounts of easy, understandable CSS.

Responsive grid layout, v2 (using box-sizing: border-box).Responsive grid layout, v1 (using negative margins).For example, if you want to create a two-column layout for most screen sizes, and a one-column layout for small screen sizes (such as phones and tablets), you can change the flex. I’m going to present four different techniques for developing your own CSS grid, and each of them are easily extendable. You learned from the CSS Media Queries chapter that you can use media queries to create different layouts for different screen sizes and devices. Let’s step back and breathe a bit, and ask ourselves a question: Are we really going to use every one of those 24 variants and the million sub-variants that “That Great Framework” ships with? Often we need only a simple flexible solution with a few variants to work in our project, and with a strong command of the basics we can extend as we see fit. This overdose of information can baffle us, and leave us wondering if frameworks like HTML9 Responsive Boilerstrap JS are really the way to go. This holds particularly true when it comes to CSS grid layouts, and there’s no shortage of frameworks deemed “the best, most lightweight to date”. These days, there’s a framework for everything, and it seems that before we can even digest one, another one is released.
