html - CSS Grid Layout not working in Edge and IE 11 even with -ms prefix -
i'me using following html markup grid.
<section class="grid"> <article class="grid-item width-2x height-2x">....</article> <article class="grid-item">....</article> <article class="grid-item">....</article> <article class="grid-item width-2x">....</article> <article class="grid-item height-2x">....</article> <article class="grid-item">....</article> <article class="grid-item">....</article> <article class="grid-item width-2x height-2x">....</article> </section>
the scss code below:
.grid { display: grid; grid-template-columns: repeat( 4, 1fr ); grid-gap: 30px; align-items: start; .grid-item { &.height-2x { grid-row: span 2; } &.width-2x { grid-column: span 2; } } }
since i'm using auto-prefixer in workflow automatically adds relevant properties -ms
prefix. can confirm via inspect element.
now, issue code works fine in chrome, firefox , opera when open page in microsoft edge or in ie 11 grid items overlapping each other @ first cell. according this site these browsers support css grid layout -ms
prefix. i've created codepen scnerio.
why not working?
.grid { display: -ms-grid; display: grid; -ms-grid-columns: (1fr)[4]; grid-template-columns: repeat(4, 1fr); -ms-grid-rows: (270px)[4]; grid-template-rows: repeat(4, 270px); grid-gap: 30px; } .grid .grid-item { background-color: #000; color: #fff; text-align: center; line-height: 270px; } .grid .grid-item.height-2x { -ms-grid-row: span 2; grid-row: span 2; } .grid .grid-item.width-2x { -ms-grid-column: span 2; grid-column: span 2; }
<section class="grid"> <article class="grid-item width-2x height-2x">....</article> <article class="grid-item">....</article> <article class="grid-item">....</article> <article class="grid-item width-2x">....</article> <article class="grid-item height-2x">....</article> <article class="grid-item">....</article> <article class="grid-item">....</article> <article class="grid-item width-2x height-2x">....</article> </section>
edge , ie11 use older version of grid specification.
chrome, safari, firefox , opera use current version of grid specification.
the problem in code using properties don't exist in older spec. adding prefixes them makes no difference.
i haven't read entire old spec, i'm not sure layout work in edge / ie11. however, here 3 problems see right off bat.
repeat()
the repeat()
notation doesn't exist in older spec, isn't supported edge , ie11. need write in row , column lengths these browsers.
instead of:
.grid { display: -ms-grid; display: grid; -ms-grid-columns: repeat( 4, 1fr ); grid-template-columns: repeat( 4, 1fr ); -ms-grid-rows: repeat( 4, 270px ); grid-template-rows: repeat( 4, 270px ); grid-gap: 30px; }
use:
.grid { display: -ms-grid; display: grid; -ms-grid-columns: 1fr 1fr 1fr 1fr; /* adjusted */ grid-template-columns: repeat( 4, 1fr ); -ms-grid-rows: 270px 270px 270px 270px; /* adjusted */ grid-template-rows: repeat( 4, 270px ); grid-gap: 30px; }
older spec reference: https://www.w3.org/tr/2011/wd-css3-grid-layout-20110407/#grid-repeating-columns-and-rows
span
the span
keyword doesn't exist in older spec, isn't supported edge , ie11. you'll have use equivalent properties these browsers.
instead of:
.grid .grid-item.height-2x { -ms-grid-row: span 2; grid-row: span 2; } .grid .grid-item.width-2x { -ms-grid-column: span 2; grid-column: span 2; }
use:
.grid .grid-item.height-2x { -ms-grid-row-span: 2; /* adjusted */ grid-row: span 2; } .grid .grid-item.width-2x { -ms-grid-column-span: 2; /* adjusted */ grid-column: span 2; }
older spec reference: https://www.w3.org/tr/2011/wd-css3-grid-layout-20110407/#grid-row-span-and-grid-column-span
grid-gap
the grid-gap
property, long-hand forms grid-column-gap
, grid-row-gap
, don't exist in older spec, aren't supported edge , ie11. you'll have find way separate boxes.
again, mentioned above, haven't read entire old spec, there may defined method. otherwise, try margins.
Comments
Post a Comment