1

I have a list of items that gets displayed in grid format. Couldn't find repeat css function compatible for IE 11.

It works in other browsers. But not in IE. In IE only 1 item gets created.

Please check this post or jsfiddle link in IE and (chrome, firefox) for output.

Jsfiddle

Below is the code.

body {
  margin: 30px;
}


/*autoprefixer will add the prefixed properties for grid and columns/rows
    we need to create tracks for gaps for IE*/

.wrapper {
  display: -ms-grid;
  display: grid;
  grid-gap: 10px;
  grid-auto-rows: 150px;
  -ms-grid-columns: 1fr 1fr 1fr 1fr;
  -ms-grid-rows: 160px 160px 160px 160px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  background-color: #fff;
  color: #444;
}

.box {
  background-color: #444;
  color: yellow;
  border-radius: 5px;
  font-size: 150%;
  text-align: center;
}
<div class="wrapper">
  <div class="box">A</div>
  <div class="box">B</div>
  <div class="box">C</div>
  <div class="box">D</div>
  <div class="box">E</div>
</div>

I checked with other stackoverflow posts but none of them worked.

Sharath
  • 2,348
  • 8
  • 45
  • 81
  • 1
    The elements are all present in the DOM: it's just IE does not know how to position them, because it does not support `repeat()`. – Terry Apr 04 '18 at 11:02
  • Look this https://stackoverflow.com/questions/45786788/css-grid-layout-not-working-in-edge-and-ie-11-even-with-ms-prefix – Nitheesh Apr 04 '18 at 11:03
  • @Nitheesh I saw the link but didn't work... – Sharath Apr 04 '18 at 11:27
  • @Terry so whtat's the alternate.. – Sharath Apr 04 '18 at 11:27
  • You need to individually specify `-ms-grid-column` for each box. – Terry Apr 04 '18 at 11:29
  • @Terry do you have any example I searched a lot but not able to find suitable example... it will be great if you can provide – Sharath Apr 04 '18 at 11:35
  • Just use `-ms-grid-column: 1` for the first column (box with A), `-ms-grid-column: 2` for the second column (box with B) and so on... there is no other way if you want grid support in IE. Otherwise, use a fallback like float or flexbox. – Terry Apr 04 '18 at 11:42
  • @Terry it worked but items gets created in single line without breaking into new line when there is no space... can you check this link ... https://jsfiddle.net/swzt01hy/8/ – Sharath Apr 04 '18 at 12:01

0 Answers0