我正在尝试使用列进行响应式布局,但在某些情况下,它们的数量正在变化。我已经设置column-count:3
了,但是当我有 4 个 div 时,它们的位置是 2x2 而不是 3x1。
当我有 7 列时会发生同样的错误,依此类推。
#content {
width: 980px;
height:1000px;
position:relative;
margin: 0 auto 0 auto;
background-color:white;
max-width: 980px;
}
#columns {
font-size:1em;
-webkit-column-count: 3;
-webkit-column-gap: 0.625em;
-webkit-column-fill: balance;
-moz-column-count: 3;
-moz-column-gap: 0.625em;
-moz-column-fill: balance;
column-count: 3;
column-gap: 0.625em;
column-fill: balance;
}
.news {
margin-bottom:0.938em;
display: inline-block;
background: blue;
-webkit-column-break-inside: avoid;
-moz-column-break-inside: avoid;
column-break-inside: avoid;
padding: 0.625em;
}
.newsheader {
width:100%;
padding-bottom: 0.75em;
}
<div id="wrapper">
<div id="content">
<div id="columns">
<div class="news">
<p class="newsheader">Lorem ipsum dolor sit amet...</p> <span class="newscontent">Lorem ipsum dolor sit amet...</span>
</div>
<div class="news">
<p class="newsheader">Lorem ipsum dolor sit amet...</p> <span class="newscontent">Lorem ipsum dolor sit amet...</span>
</div>
<div class="news">
<p class="newsheader">Lorem ipsum dolor sit amet...</p> <span class="newscontent">Lorem ipsum dolor sit amet...</span>
</div>
<div class="news">
<p class="newsheader">Lorem ipsum dolor sit amet...</p> <span class="newscontent">Lorem ipsum dolor sit amet...</span>
</div>
</div>
</div>
</div>
这是一个 JSFiddle 演示:http: //jsfiddle.net/BmG44/