更新:适用于所有浏览器的最新代码位于此 JSFiddle - https://jsfiddle.net/webvitaly/yu00ugft/5/
我正在尝试使用纯 CSS 方法制作响应式列。
我有一个问题,列有时在顶部有间隙/边距。
尝试探索的 JSFiddle 链接 - https://jsfiddle.net/webvitaly/yu00ugft/
如何解决?
CSS:
.fx-columns {
background: yellow;
-webkit-column-count: 2;
-moz-column-count: 2;
column-count: 2;
-webkit-column-gap: 30px;
-moz-column-gap: 30px;
column-gap: 30px;
}
.fx-columns-3 {
-webkit-column-count: 3;
-moz-column-count: 3;
column-count: 3;
}
.fx-columns-4 {
-webkit-column-count: 4;
-moz-column-count: 4;
column-count: 4;
}
.fx-columns .fx-column {
-webkit-column-break-inside: avoid;
break-inside: avoid;
background: pink;
clear: both;
margin-bottom: 20px;
}
HTML:
<div class="fx-columns fx-columns-4">
<div class="fx-column">
<h3>Header</h3>
<p>Text paragraph</p>
</div>
<div class="fx-column">
<h3>Header</h3>
<p>Text paragraph</p>
<p>Text paragraph</p>
<p>Text paragraph</p>
</div>
<div class="fx-column">
<h3>Header</h3>
<p>Text paragraph</p>
<p>Text paragraph</p>
</div>
<div class="fx-column">
<h3>Header</h3>
<p>Text paragraph</p>
<p>Text paragraph</p>
<p>Text paragraph</p>
<p>Text paragraph</p>
</div>
<div class="fx-column">
<h3>Header</h3>
<p>Text paragraph</p>
</div>
<div class="fx-column">
<h3>Header</h3>
<p>Text paragraph</p>
<p>Text paragraph</p>
</div>
<div class="fx-column">
<h3>Header</h3>
<p>Text paragraph</p>
<p>Text paragraph</p>
<p>Text paragraph</p>
</div>
<div class="fx-column">
<h3>Header</h3>
<p>Text paragraph</p>
</div>
<div class="fx-column">
<h3>Header</h3>
<p>Text paragraph</p>
<p>Text paragraph</p>
</div>
<div class="fx-column">
<h3>Header</h3>
<p>Text paragraph</p>
<p>Text paragraph</p>
<p>Text paragraph</p>
</div>
</div>