我正在构建一种帖子网格滑块,它会在CSS网格中显示4个框。我已经构建了所有内容,并且按预期工作,但在Firefox中无法正常工作。
Firefox和Safari都存在显示网格高度的问题。它们的结果为0或1像素。为了解决这个问题,我使用了display:flex并将flex-flow设置为row wrap。这在Safari中有效,但在Firefox中无效。当我从容器中删除flex时,它在Firefox中有效,但在Safari中无效。
Edge和Chrome两种方式都可以正常工作。我正在寻找解决方案并尝试解决它,但结果仍然相同。
我使用padding-top和position absolute来实现'成比例'响应式网格及其项目。
谢谢您的回复。 https://codepen.io/Mariopa/pen/ELjqYr
Firefox和Safari都存在显示网格高度的问题。它们的结果为0或1像素。为了解决这个问题,我使用了display:flex并将flex-flow设置为row wrap。这在Safari中有效,但在Firefox中无效。当我从容器中删除flex时,它在Firefox中有效,但在Safari中无效。
Edge和Chrome两种方式都可以正常工作。我正在寻找解决方案并尝试解决它,但结果仍然相同。
我使用padding-top和position absolute来实现'成比例'响应式网格及其项目。
谢谢您的回复。 https://codepen.io/Mariopa/pen/ELjqYr
<div class="post-grid-slider">
<div class="post-grid-wrapper">
<div class="post-grid">
<div class="post-grid__item">
<a href="#" target="_self" rel="nofollow" class="post-grid__link">
<div class="post-grid__thumbnail" style="background-image:url(http://patlevic.sk/demopic/Inoutic-1024x683)"></div>
<div class="subcategory"><span >Category</span></div>
<h2 class="post-grid__title">Title</h2>
</a>
</div>
<div class="post-grid__item">
<a href="#" target="_self" rel="nofollow" class="post-grid__link">
<div class="post-grid__thumbnail" style="background-image:url(http://patlevic.sk/demopic/kinds-of-food-3320746_1920-1024x683)"></div>
<div class="subcategory"><span>Category</span></div>
<h2 class="post-grid__title">Title</h2>
</a>
</div>
<div class="post-grid__item">
<a href="#" target="_self" rel="nofollow" class="post-grid__link">
<div class="post-grid__thumbnail" style="background-image:url(http://patlevic.sk/demopic/leaf-397870_1920-1024x768)"></div>
<div class="subcategory"><span>Category</span></div>
<h2 class="post-grid__title">Title</h2>
</a>
</div>
<div class="post-grid__item">
<a href="#" target="_self" rel="nofollow" class="post-grid__link">
<div class="post-grid__thumbnail" style="background-image:url(http://patlevic.sk/demopic/grape-hyacinth-1024x679)"></div>
<div class="subcategory"><span>Category</span></div>
<h2 class="post-grid__title">Title</h2>
</a>
</div>
</div>
</div>
</div>
CSS
.post-grid-slider {
display:-webkit-box;
display:-ms-flexbox;
display:flex;
-webkit-box-orient:horizontal;
-webkit-box-direction:normal;
-ms-flex-flow:row nowrap;
flex-flow:row nowrap;
height:100%;
padding: 0 15px;
}
.post-grid-wrapper {
-webkit-box-flex: 1;
-ms-flex: 1 0 100%;
flex: 1 0 100%;
position: relative;
width:100%;
padding-top: 25%;
}
.post-grid {
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
display: -ms-grid;
display: grid;
-ms-grid-columns: auto;
grid-template-columns: auto;
-ms-grid-rows: 50% 50%;
grid-template-rows: 50% 50%;
grid-column-gap: 0.0625rem;
grid-row-gap: 0.0625rem;
width: 100%;
height: 100%;
}
.post-grid__item {
position: relative;
overflow: hidden;
}
.post-grid__item:nth-child(1) {
-ms-grid-column: 1;
-ms-grid-column-span: 6;
grid-column: 1/7;
-ms-grid-row: 1;
-ms-grid-row-span: 2;
grid-row: 1/3;
}
.post-grid__item:nth-child(2) {
-ms-grid-column: 7;
-ms-grid-column-span: 4;
grid-column: 7/11;
-ms-grid-row: 1;
-ms-grid-row-span: 1;
grid-row: 1/2;
}
.post-grid__item:nth-child(3) {
-ms-grid-column: 7;
-ms-grid-column-span: 2;
grid-column: 7/9;
-ms-grid-row: 2;
-ms-grid-row-span: 1;
grid-row: 2/3;
}
.post-grid__item:nth-child(4) {
-ms-grid-column: 9;
-ms-grid-column-span: 2;
grid-column: 9/11;
-ms-grid-row: 2;
-ms-grid-row-span: 1;
grid-row: 2/3;
}
.post-grid__link {
position: relative;
display: block;
width: 100%;
height: 100%;
overflow: hidden;
}
.post-grid__link:hover > .post-grid__thumbnail {
webkit-transform: scale(1);
-moz-transform: scale(1);
-o-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
}
.post-grid__thumbnail {
width: 100%;
height: 100%;
margin: 0px;
position: absolute;
background-repeat: no-repeat;
background-position: left center;
background-size: cover;
-webkit-transition: All .7s ease;
-moz-transition: All .7s ease;
-o-transition: All .7s ease;
transition: All .5s ease;
-webkit-transform: scale(1.20);
-moz-transform: scale(1.20);
-o-transform: scale(1.20);
-ms-transform: scale(1.20);
transform: scale(1.20);
}
.post-grid__thumbnail::after {
content: "";
position: absolute;
left: 0;
right: 0;
bottom: 0;
height: 50%;
-webkit-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
transition: opacity 0.2s;
background-image: -webkit-gradient(linear, left top, left bottom, from(transparent), to(rgba(0, 0, 0, 0.8)));
background-image: -webkit-linear-gradient(top, transparent, rgba(0, 0, 0, 0.8));
background-image: -o-linear-gradient(top, transparent, rgba(0, 0, 0, 0.8));
background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.8));
}
.subcategory {
position: absolute;
top: 15px;
left: 15px;
display: inline-block;
padding: 0 0.5rem;
background: #A20315;
color: #fff;
font-size: 0.75rem;
font-weight: 500;
text-transform: uppercase;
z-index: 1;
line-height: 24px;
}
.post-grid__title {
position: absolute;
left: 15px;
bottom: 15px;
text-shadow: 0 1px 5px rgba(0,0,0,0.4);
margin: 0;
font-weight: 500;
color: #fff;
}