调整柔性盒

时间:2014-04-26 06:53:47

标签: html css3 flexbox

我目前在容器内安排盒子的尝试已经产生了这个输出。

enter image description here

但我想要实现的是,

  • 用最大数量的方框填充每一行,但每个方框都有固定的填充和边距。我相信我已经实现了这一点。
  • 我需要每行中的各个方框来覆盖剩余的空格,间隙只有1px。

例如:第一行,这些应该是我每个之间只有1px的差距。或者采取最后一行,只有一个盒子,它应该覆盖容器的整个宽度。

此处的代码: http://codepen.io/anon/pen/rbkdh

此处的代码仅供参考:

HTML

<ul class="flex-container">
  <li class="flex-item">1, One One One</li>
  <li class="flex-item">2, Two Two</li>
  <li class="flex-item">3, Three</li>
  <li class="flex-item">4, Four Four Four Four Four</li>
  <li class="flex-item">5, Five Five</li>
  <li class="flex-item">6, Six</li>
</ul>

CSS

.flex-container {
  padding: 0;
  margin: 0;
  list-style: none;
  border: 1px solid;
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;

  flex-direction: row;
  flex-wrap: wrap;
  -webkit-flex-flow: row wrap;
  justify-content: space-between;
  align-items: stretch;
  align-content: stretch;

  max-width:400px; /*only width is fixed*/
}

.flex-item {
  background: green;
  padding-top: 10px;
  padding-bottom: 10px;
  padding-left: 15px;
  padding-right: 15px;
  margin: 2px;

  line-height: 2em;
  color: white;
  font-weight: bold;
  font-size: 1em;
  text-align: center;

  flex-grow:1;
} 

1 个答案:

答案 0 :(得分:1)

.flex-item flex-grow:1。请记住将flex应用于 child ,而不是容器。

http://codepen.io/anon/pen/jkLCs

enter image description here