CSS控制行上

时间:2017-10-15 13:28:53

标签: css css3 flexbox

在示例中,我有一个包含div项的块div,div项被设置为圆形。

我想使用flex将它们显示为两行三行。

我让它们以两行显示三行,但这些物品被拉伸变形。

如何将项目保留为圆圈并将其显示为两行三个

body{
  background: grey;
}

.block{
  background: white;
  display: flex;
  height: 400px;
  flex-flow: row wrap;
  justify-content: space-around;
  padding: 20px;
  position: absolute;
  right: 40px;
  top: 80px;
  width: 540px;
  z-index: 1000;
}

.block__item{
    background: red;
    border-radius: 80px;
    color: white;
    flex-basis: 33%;
    height: 80px;
    text-align: center;
    width: 80px;
  }
<div class="block">
    <div class="block__item">1</div>
    <div class="block__item">2</div>
    <div class="block__item">3</div>
    <div class="block__item">4</div>
    <div class="block__item">5</div>
    <div class="block__item">6</div>
</div>

1 个答案:

答案 0 :(得分:1)

如果你将圆圈嵌套在block--item类中,你可以将它们放在里面而不会扭曲它们的形状:

&#13;
&#13;
body {
  background: grey;
}

.block {
  background: white;
  display: flex;
  height: 400px;
  flex-flow: row wrap;
  justify-content: space-around;
  padding: 20px;
  position: absolute;
  right: 40px;
  top: 80px;
  width: 540px;
  z-index: 1000;
}

.block__item {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 33%;
}

.block__item_circle {
  display: flex;
  background: red;
  justify-content: center;
  align-items: center;
  border-radius: 80px;
  color: white;
  height: 80px;
  text-align: center;
  width: 80px;
}
&#13;
<div class="block">
  <div class="block__item">
    <div class="block__item_circle">1</div>
  </div>
  <div class="block__item">
    <div class="block__item_circle">2</div>
  </div>
  <div class="block__item">
    <div class="block__item_circle">3</div>
  </div>
  <div class="block__item">
    <div class="block__item_circle">4</div>
  </div>
  <div class="block__item">
    <div class="block__item_circle">5</div>
  </div>
  <div class="block__item">
    <div class="block__item_circle">6</div>
  </div>
</div>
&#13;
&#13;
&#13;