如何解决IE11 - CSS 网格 - Justify-items:中心不工作
我知道有一个属性可以将 IE 中的项目与 -ms-grid-row-align
&
-ms-grid-column-align
但我正在寻找 justify-content
或 justify-items
属性,以便我可以一次将所有项目居中对齐。
有什么办法可以在 IE11 上运行 ? 如果没有,有什么替代方法?
下面的代码片段将使内容居中对齐,
- Firefox 和 chrome
.section_test {
display: grid;
display: -ms-grid;
justify-content: center;
}
.section_test > article {
}
<html>
<head>
<title>test</title>
</head>
<body>
<section class="section_test">
<article>
Test the Article
</article>
</section>
</body>
</html>
谢谢。
解决方法
您可以尝试使用绝对和变换的旧组合。
.section_test {
position: relative;
height: 100px;
background-color: gray;
}
article {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
<section class="section_test">
<article>
Test the Article
</article>
</section>
您只能使用媒体查询以 css 样式定位 IE。因为 -ms-high-contrast
是 Microsoft 特定的(并且仅在 IE 10+ 中可用),所以它只能在 Internet Explorer 10+ 中解析。你可以参考我的代码示例:
.section_test {
display: grid;
display: -ms-grid;
justify-content: center;
}
@media all and (-ms-high-contrast: none),(-ms-high-contrast: active) {
/* IE10+ CSS styles go here */
.section_test {
position: relative;
height: 100px;
}
article {
position: absolute;
top: 10%;
left: 50%;
transform: translate(-50%,-50%);
}
}
<section class="section_test">
<article>
Test the Article
</article>
</section>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。