{"id":273207,"date":"2018-07-06T07:03:23","date_gmt":"2018-07-06T14:03:23","guid":{"rendered":"http:\/\/css-tricks.com\/?p=273207"},"modified":"2020-12-19T03:34:31","modified_gmt":"2020-12-19T11:34:31","slug":"css-grid-in-ie-faking-an-auto-placement-grid-with-gaps","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/css-grid-in-ie-faking-an-auto-placement-grid-with-gaps\/","title":{"rendered":"CSS Grid in IE: Faking an Auto-Placement Grid with Gaps"},"content":{"rendered":"
This is the third and final part in a three-part series about using CSS grid safely in Internet Explorer 11 (IE11) without going insane.<\/p>\n
In Part 1<\/a>, I covered some of the common misconceptions that people have about IE11\u2019s native CSS grid implementation. In Part 2<\/a>, I showed the world how easy it actually is to write IE-friendly CSS grid code.<\/p>\n Today, I\u2019m going step away from CSS grid for a moment to show you a flexbox technique that replicates basic CSS grid auto-placement functionality. This CSS grid replica will even look like a <\/p>\n I\u2019ll use this basic HTML as an example:<\/p>\n The first thing that we need to do in the CSS is make sure that all of the boxes are being sized based on That will be applied globally. If you are working on an an existing project that doesn\u2019t have Next, you will need to turn on some flexbox settings:<\/p>\n Now, set up your column widths. We\u2019ll make ourselves a simple three-column grid:<\/p>\ngrid-gap<\/code> has been applied to it. I need to be super clear though: this is not<\/em> about how to make actual CSS grid auto-placement work in IE.<\/p>\n
Article Series:<\/h4>\n
\n
How to make a fake grid with cell gaps<\/h3>\n
Step 1: HTML<\/h4>\n
\n\n\n<div class=\"grid-wrapper\">\n\n\n\n\n<div class=\"grid\">\n\n\n\n<div class=\"grid-cell\"><\/div>\n\n\n\n\n\n\n<div class=\"grid-cell\"><\/div>\n\n\n\n\n\n\n<div class=\"grid-cell\"><\/div>\n\n\n\n\n\n\n<div class=\"grid-cell\"><\/div>\n\n\n\n\n\n\n<div class=\"grid-cell\"><\/div>\n\n\n\n\n\n\n<div class=\"grid-cell\"><\/div>\n\n\n\n<\/div>\n\n\n\n \n<\/div>\n\n<\/code><\/pre>\n
Step 2: Border-box box sizing<\/h4>\n
border-box<\/code> rather than
content-box<\/code>. The best way to do that is using the
box-sizing: border-box<\/code> inheritance technique<\/a>:<\/p>\n
html {\n box-sizing: border-box;\n}\n\n*, *::before, *::after {\n box-sizing: inherit;\n}<\/code><\/pre>\n
box-sizing<\/code> set to
border-box<\/code>, then change
html<\/code> in the snippet to a selector that targets the element you want to turn into a grid.<\/p>\n
Step 3: Flex<\/h4>\n
.grid {\n \/* Forces equal cell heights *\/\n display: flex;\n flex-wrap: wrap;\n}<\/code><\/pre>\n
Step 4: Widths<\/h4>\n
.grid-cell {\n \/* Sets column count *\/\n width: calc(100% \/ 3); \/* calc() method *\/\n width: 33.33%; \/* percentage method *\/\n}<\/code><\/pre>\n