gpt4 book ai didi

html - 使用 CSS Masonry 布局,如何设置中断和移动到新列的高度?

转载 作者:行者123 更新时间:2023-11-28 07:30:48 25 4
gpt4 key购买 nike

使用下面的 CSS Masonry 布局,在 Firefox 中,第一列显示 card 1card 2,然后从 card 3 开始第 2 列>。但在 Chrome 中,第一列显示 card 1card 2 card 3 然后第 2 列开始于卡片 4

columns 元素上设置 height 和 max-height 不起作用。我如何设置将卡片移动到下一列的高度,以便它在所有现代浏览器(Chrome、Safari 和 Firefox)中都相同?

此处演示:http://jsfiddle.net/xfobotx6/

CSS:

.wrapper
{
position: relative;
width: 60em;
background-color: red;
margin: 1em;
margin-left: auto;
margin-right: auto;
}

.columns
{
position: relative;
padding: 0em;
-moz-column-count: 3;
-webkit-column-count: 3;
column-count: 3;
-moz-column-gap: 1em;
-webkit-column-gap: 1em;
column-gap: 1em;
font-size: 1em;
}

.card
{
position: relative;
width: 100%;
padding: 1.5em;
margin-bottom: 1em;
-webkit-column-break-inside: avoid;
page-break-inside: avoid;
break-inside: avoid;
column-break-inside: avoid;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-shadow: 0px 1px 1px 0px rgba(0, 0, 0, 0.18);
background: #efefef;
display: inline-block;
}

#card1
{

height: 200px;
}

#card2
{

height: 200px;
}

#card3
{

height: 160px;
}

#card4
{

height: 200px;
}

#card5
{

height: 200px;
}

#card6
{

height: 200px;
}

HTML:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<link href="stylesheets/reset.css" media="screen" rel="stylesheet" type="text/css" />
<link href="stylesheets/main.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="wrapper">
<div class="columns">
<div id="card1" class="card">Card 1 here</div>
<div id="card2" class="card">Card 2 here</div>
<div id="card3" class="card">Card 3 here</div>
<div id="card4" class="card">Card 4 here</div>
<div id="card5" class="card">Card 5 here</div>
<div id="card6" class="card">Card 6 here</div>
</div>
</div>
</body>
</html>

最佳答案

这似乎在所有浏览器中都没有实现,但它是规范的一部分:

http://www.quirksmode.org/css/columns/breaks.html

该规范用于将 break-before: column 放置在列中的一个元素上(并且使用 CSS,您可以让每 nth-item 发生一次) , 但目前还没有浏览器实现这一点。

-webkit-column-break-before: always;
break-before: column;

关于html - 使用 CSS Masonry 布局,如何设置中断和移动到新列的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31524576/

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