CSS Grid Layout Not Working in IE11 Even with Prefixes
Despite using auto-prefixer to add prefixes to relevant CSS properties, CSS Grid layout appears to malfunction in IE11. This issue arises due to the browser's outdated Grid specification.
Outdated Grid Specification
IE11 implements an older version of the Grid specification, which lacks some key properties introduced in later versions. Specifically, the following properties are not supported by IE11:
Solution
To address this issue, the code should be updated to use the correct syntax and properties for the older grid spec. The following changes are necessary:
1. Replace repeat() with Explicit Track Declarations
Instead of using the repeat() function, explicitly declare row and column tracks using comma-separated values:
.grid { -ms-grid-columns: 1fr 1fr 1fr 1fr; grid-template-columns: repeat(4, 1fr); -ms-grid-rows: 270px 270px 270px 270px; grid-template-rows: repeat(4, 270px); }
2. Use Spanning Properties
Replace span with its long-hand forms grid-row-span and grid-column-span:
.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; }
3. Remove Grid-Gap in IE11
IE11 does not support the grid-gap property. Consider using margins or padding for spacing instead:
.grid .grid-item { margin: 30px; }
Additional Note
IE11 also lacks support for automatic placement of grid items. To ensure proper placement, explicitly specify the grid row and column positions for each item using the -ms-grid-row and -ms-grid-column properties.
The above is the detailed content of Why Isn't My CSS Grid Layout Working in IE11, Even with Autoprefixer?. For more information, please follow other related articles on the PHP Chinese website!