CSS列数不会填满整个区域

时间:2016-07-04 06:51:31

标签: css css3 column-count

我尝试使用css3规则column-count显示8列中的项目。但是,有时它会显示6,有时是7.我试图为这些项目设置一个特定的宽度,似乎没有任何效果。

Click here to see the Fiddle



body {margin: 0;}
.container {
  margin: auto;
  padding: 0 15px;
  background: #eee;
}
@media (min-width: 768px) {
  .container {width: 750px;}
}
@media (min-width: 992px) {
  .container {width: 970px;}
}
@media (min-width: 1200px) {
  .container {width: 1170px;}
}
.brick-wall {
  -webkit-column-gap: 0;
  -webkit-column-fill: balance;
  -moz-column-gap: 0;
  -moz-column-fill: balance;
  column-gap: 0;
  column-fill: balance;
  -webkit-column-count: 8;
  -moz-column-count: 8;
  column-count: 8;
}
.brick {
  -webkit-column-break-inside: avoid;
  -moz-column-break-inside: avoid;
  column-break-inside: avoid;
  text-align: center;
}
.brick-wall .brick .brick-content {
  border: 1px solid #000;
  display: inline-block;
  vertical-align: top;
  width: 95%;
  margin: 5px 0;
}

<div class="container">
  <div class="brick-wall">
    <script type="text/javascript">
      for(i = 0;i < 17;i++) document.write('<div class="brick"><div class="brick-content"><br/>' + (i + 1) + '<br/></div></div>');
    </script>
  </div>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

使用flex布局将解决列布局问题

.brick-wall{
 display: flex;
 font-size:18px;
  flex-wrap: wrap;
 }
 .brick {
   width: 11.5%;
   margin: .5%;
   text-align: center;
   border: 1px solid #000;
   display: block;
 }

https://jsfiddle.net/yh4yvoe3/9/