我用HTML / CSS创建了一个砌体样式网格。为此,我使用了
display:grid属性以及“ grid-row”和“ grid-column”。
这在Chrome,Firefox和Edge上很好用,尚未在Safari上尝试过,但是不幸的是,当它在IE 11浏览器中呈现时会出现问题。 并没有如附带的笔所示那样获得漂亮的网格布局,它只是在彼此顶部显示4个1x1列。
我可以为CSS类分配任何IE特定属性,以使其在所有浏览器中正确显示吗?
#container {
display:inline-block;
overflow: hidden; /* clip the excess when child gets bigger than parent */
}
#container img {
display: block;
transition: transform .4s; /* smoother zoom */
}
#container:hover img {
transform: scale(1.3);
transform-origin: 50% 50%;
}
.wrapper {
display: grid;
grid-gap: 0px;
grid-template-columns: 33% 33% 33%;
grid-template-rows: 400px 400px;
color: #000;
}
.a {
grid-column: 1;
grid-row: 1/3;
text-align:center;
color:#fff;
display:block;
position:relative;
overflow:hidden;
}
.b {
grid-column: 2 / span 2;
grid-row: 1;
color:#fff;
position:relative;
overflow:hidden;
}
.c {
grid-column: 2;
grid-row: 2;
color:#fff;
position:relative;
overflow:hidden;
}
.d {
grid-column: 3;
grid-row: 2;
color:#fff;
position:relative;
overflow:hidden;
}
.box {
border-radius: 0px;
padding: 10px;
font-size: 150%;
display:block;
position:relative;
}
.ctr {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%)
}
.imex-btn {
background-color: #4080fa;
border: none;
color: white;
padding: 10px 30px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin-top: 70px;
cursor: pointer;
font-family: "Century Gothic";
}
.imex-btn:hover {
background-color: #000;
color: #4080fa;
}
<div class="wrapper">
<div class="box a">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x900
C/O https://placeholder.com/">
<div class="ctr"><h2 class="white">BOX A<h2>
</div>
<a href="#" class="ctr imex-btn">VIEW NOW</a>
</div>
</div>
<div class="box b">
<div id="container">
<img id="image" src="https://via.placeholder.com/1200x900/C/O https://placeholder.com/">
<div class="ctr"><h2 class="white">BOX B</h2>
</div>
<a href="#" class="ctr imex-btn">VIEW NOW</a>
</div>
</div>
<div class="box c">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x500
C/O https://placeholder.com/">
<div class="ctr"><h2 class="white" style="text-align:center">BOX C</h2>
</div>
<a href="#" class="ctr imex-btn">READ MORE</a>
</div>
</div>
<div class="box d">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x500
C/O https://placeholder.com/">
<div class="ctr"><h2 class="white" style="text-align:center">BOX D</h2>
</div>
<a href="#" class="ctr imex-btn">READ MORE</a>
</div>
</div>
</div>
答案 0 :(得分:1)
尝试从
更改CSS网格模板列:33%33%33%;
收件人
grid-template-columns:1fr 1fr 1fr;
答案 1 :(得分:1)
某些元素由于其标准的执行而无法在IE11上正确呈现。 尝试为显示元素添加-ms-前缀,例如display:grid,grid-column和grid-row。
在旧版本的Safari上进行测试时,您可能会遇到相同的问题(在这种情况下,请尝试-webkit前缀)。
答案 2 :(得分:1)
我添加了一些CSS使其在IE中工作。请注意CSS中添加的-ms-
前缀。您也可以参考this article,其中介绍了如何在IE中支持CSS网格。
#container {
display: inline-block;
overflow: hidden; /* clip the excess when child gets bigger than parent */
}
#container img {
display: block;
transition: transform .4s; /* smoother zoom */
}
#container:hover img {
transform: scale(1.3);
transform-origin: 50% 50%;
}
.wrapper {
display: -ms-grid;
display: grid;
grid-gap: 0px;
grid-template-columns: 33% 33% 33%;
-ms-grid-columns: 33% 33% 33%;
grid-template-rows: 400px 400px;
-ms-grid-rows: 400px 400px;
color: #000;
}
.a {
grid-column: 1;
grid-row: 1/3;
-ms-grid-column: 1;
-ms-grid-row-span: 2;
text-align: center;
color: #fff;
display: block;
position: relative;
overflow: hidden;
}
.b {
grid-column: 2 / span 2;
grid-row: 1;
-ms-grid-row:1;
-ms-grid-column-span: 2;
-ms-grid-column:2;
color: #fff;
position: relative;
overflow: hidden;
}
.c {
grid-column: 2;
grid-row: 2;
-ms-grid-column:2;
-ms-grid-row:2;
color: #fff;
position: relative;
overflow: hidden;
}
.d {
grid-column: 3;
grid-row: 2;
-ms-grid-column:3;
-ms-grid-row:2;
color: #fff;
position: relative;
overflow: hidden;
}
.box {
border-radius: 0px;
padding: 10px;
font-size: 150%;
display: block;
position: relative;
}
.ctr {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%)
}
.imex-btn {
background-color: #4080fa;
border: none;
color: white;
padding: 10px 30px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin-top: 70px;
cursor: pointer;
font-family: "Century Gothic";
}
.imex-btn:hover {
background-color: #000;
color: #4080fa;
}
<div class="wrapper">
<div class="box a">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x900
C/O https://placeholder.com/">
<div class="ctr">
<h2 class="white">BOX A</h2>
</div>
<a href="#" class="ctr imex-btn">VIEW NOW</a>
</div>
</div>
<div class="box b">
<div id="container">
<img id="image" src="https://via.placeholder.com/1200x900/C/O https://placeholder.com/">
<div class="ctr">
<h2 class="white">BOX B</h2>
</div>
<a href="#" class="ctr imex-btn">VIEW NOW</a>
</div>
</div>
<div class="box c">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x500
C/O https://placeholder.com/">
<div class="ctr">
<h2 class="white" style="text-align:center">BOX C</h2>
</div>
<a href="#" class="ctr imex-btn">READ MORE</a>
</div>
</div>
<div class="box d">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x500
C/O https://placeholder.com/">
<div class="ctr">
<h2 class="white" style="text-align:center">BOX D</h2>
</div>
<a href="#" class="ctr imex-btn">READ MORE</a>
</div>
</div>
</div>