gpt4 book ai didi

CSS Grid 在 Firefox 和 Safari 中不起作用

转载 作者:行者123 更新时间:2023-12-04 21:31:23 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Why is percentage height not working on my div? [duplicate]

(2 个回答)



Chrome / Safari not filling 100% height of flex parent

(5 个回答)


4年前关闭。




我正在构建一种后网格 slider ,它将在 CSS 网格中显示 4 个框。我建立了一切,它按预期工作,但它在 Firefox 中不起作用。

Firefox 和 Safari 都存在显示网格高度的问题。它们导致 0 或 1px。为了解决这个问题,我使用了 display:flex 和 flex-flow 设置为换行。这在 Safari 中有效,但在 Firefox 中无效。当我从容器中删除 flex 时,它在 Firefox 中有效,但在 Safari 中无效。

Edge 和 Chrome 两种方式都很好。我迷失在寻找解决方案并尝试解决它,但结果仍然相同。

我正在使用 padding-top 和 position absolute 来“按比例”响应网格及其元素。

谢谢您的回复。
https://codepen.io/Mariopa/pen/ELjqYr

HTML

<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;
}

最佳答案

我突然发现了一个解决方案。我从容器和包装器中删除了 flexbox。我添加了 height:0;包装。它似乎在所有浏览器中都按预期工作。

我已经更新了 codepen 演示。

.post-grid-slider {
height:100%;
padding: 0 15px;
}

.post-grid-wrapper {
position: relative;
width:100%;
height: 0;
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-family: 'Roboto';
font-weight: 500;
color: #fff;
}

关于CSS Grid 在 Firefox 和 Safari 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49954587/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com