gpt4 book ai didi

CSS 网格 : grid-row not working in Chrome browser

转载 作者:行者123 更新时间:2023-11-28 08:44:16 26 4
gpt4 key购买 nike

我已经列出了像砖石一样具有固定高度的 div。该代码在 Firefox 中有效,但在 Chrome 中无效。我提到的引用代码是 CSS-only masonry layout .

Chrome 浏览器 enter image description hereMozila 火狐浏览器 enter image description here

.container {
width: 1080px;
margin: 0 auto;
}

.grid-container {
display: grid;
grid-auto-rows: 1px;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.grid-item {
display: flex;
align-items: center;
justify-content: center;
border: 1px solid;
font-size: 50px;
margin: 5px;
}

.grid-row-200 {
grid-row: span 200;
}

.grid-row-225 {
grid-row: span 225;
}

.grid-row-250 {
grid-row: span 250;
}

.grid-row-275 {
grid-row: span 275;
}

.grid-row-300 {
grid-row: span 300;
}

.grid-row-350 {
grid-row: span 350;
}
<div class="container">
<div class="grid-container">
<div class="grid-item grid-row-200">200px</div>
<div class="grid-item grid-row-300">300px</div>
<div class="grid-item grid-row-225">225px</div>
<div class="grid-item grid-row-250">250px</div>
<div class="grid-item grid-row-275">275px</div>
<div class="grid-item grid-row-350">350px</div>
<div class="grid-item grid-row-300">300px</div>
<div class="grid-item grid-row-250">250px</div>
<div class="grid-item grid-row-350">350px</div>
<div class="grid-item grid-row-275">275px</div>
<div class="grid-item grid-row-225">225px</div>
<div class="grid-item grid-row-250">250px</div>
<div class="grid-item grid-row-350">350px</div>
<div class="grid-item grid-row-250">250px</div>
<div class="grid-item grid-row-300">300px</div>
<div class="grid-item grid-row-250">250px</div>
<div class="grid-item grid-row-275">275px</div>
<div class="grid-item grid-row-350">350px</div>
<div class="grid-item grid-row-225">225px</div>
</div>
</div>

最佳答案

由于您所有的 span 都是 5 的乘数,您可以尝试使用较小的数字来避免此 bug 并增加 网格自动行

.container {
width: 1080px;
margin: 0 auto;
}

.grid-container {
display: grid;
grid-auto-rows: 5px;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.grid-item {
display: flex;
align-items: center;
justify-content: center;
border: 1px solid;
font-size: 50px;
margin: 5px;
}

.grid-row-200 {
grid-row: span 40;
}

.grid-row-225 {
grid-row: span 45;
}

.grid-row-250 {
grid-row: span 50;
}

.grid-row-275 {
grid-row: span 55;
}

.grid-row-300 {
grid-row: span 60;
}

.grid-row-350 {
grid-row: span 70;
}
<div class="container">
<div class="grid-container">
<div class="grid-item grid-row-200">200px</div>
<div class="grid-item grid-row-300">300px</div>
<div class="grid-item grid-row-225">225px</div>
<div class="grid-item grid-row-250">250px</div>
<div class="grid-item grid-row-275">275px</div>
<div class="grid-item grid-row-350">350px</div>
<div class="grid-item grid-row-300">300px</div>
<div class="grid-item grid-row-250">250px</div>
<div class="grid-item grid-row-350">350px</div>
<div class="grid-item grid-row-275">275px</div>
<div class="grid-item grid-row-225">225px</div>
<div class="grid-item grid-row-250">250px</div>
<div class="grid-item grid-row-350">350px</div>
<div class="grid-item grid-row-250">250px</div>
<div class="grid-item grid-row-300">300px</div>
<div class="grid-item grid-row-250">250px</div>
<div class="grid-item grid-row-275">275px</div>
<div class="grid-item grid-row-350">350px</div>
<div class="grid-item grid-row-225">225px</div>
</div>
</div>

你仍然可以减少更多:

.container {
width: 1080px;
margin: 0 auto;
}

.grid-container {
display: grid;
grid-auto-rows: 25px;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.grid-item {
display: flex;
align-items: center;
justify-content: center;
border: 1px solid;
font-size: 50px;
margin: 5px;
}

.grid-row-200 {
grid-row: span 8;
}

.grid-row-225 {
grid-row: span 9;
}

.grid-row-250 {
grid-row: span 10;
}

.grid-row-275 {
grid-row: span 11;
}

.grid-row-300 {
grid-row: span 12;
}

.grid-row-350 {
grid-row: span 14;
}
<div class="container">
<div class="grid-container">
<div class="grid-item grid-row-200">200px</div>
<div class="grid-item grid-row-300">300px</div>
<div class="grid-item grid-row-225">225px</div>
<div class="grid-item grid-row-250">250px</div>
<div class="grid-item grid-row-275">275px</div>
<div class="grid-item grid-row-350">350px</div>
<div class="grid-item grid-row-300">300px</div>
<div class="grid-item grid-row-250">250px</div>
<div class="grid-item grid-row-350">350px</div>
<div class="grid-item grid-row-275">275px</div>
<div class="grid-item grid-row-225">225px</div>
<div class="grid-item grid-row-250">250px</div>
<div class="grid-item grid-row-350">350px</div>
<div class="grid-item grid-row-250">250px</div>
<div class="grid-item grid-row-300">300px</div>
<div class="grid-item grid-row-250">250px</div>
<div class="grid-item grid-row-275">275px</div>
<div class="grid-item grid-row-350">350px</div>
<div class="grid-item grid-row-225">225px</div>
</div>
</div>

关于CSS 网格 : grid-row not working in Chrome browser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54956609/

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