将单个元素移动到Flex容器的末尾

时间:2015-03-20 21:19:13

标签: css zurb-foundation flexbox

我以为我可以将这个按钮移到弹性盒的末端。

我已将父级设置为display: flex;,然后我认为我可以使用align-self: flex-end;

将一个元素作为目标并将其固定到容器的底部

它不起作用。这是我的笔:My Codepen illustrating the issue

 <div class="row services">
  <div class="small-3 panel columns service">
    <i class="fa fa-thumbs-o-up"></i>
    <h3>SUSPENDISSE</h3><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. A, ad?</p>
    <div class="button">Read More</div>
  </div>
  <div class="small-3 panel columns service">
    <i class="fa fa-key"></i>
    <h3>MAECENAS</h3><p>Porro quibusdam nostrum eaque, quasi laudantium delectus quaerat cumque, quos.</p>
    <div class="button">Read More</div>
  </div>
  <div class="small-3 panel columns service">
    <i class="fa fa-flag"></i>
    <h3>ALIQUAM</h3><p>Iste architecto omnis, esse facere quod ratione, officia veritatis fugit.</p>
    <div class="button">Read More</div>
  </div>
  <div class="small-3 panel columns service">
    <i class="fa fa-flask"></i>
    <h3>HABITASSE</h3><p>Ducimus voluptates assumenda, illum adipisci sed quaerat est ipsum nisi.</p>
    <div class="button">Read More</div>
  </div>
</div>

.services {
  display: flex;

}
.service {
  flex-direction: column;
}
.button {
  align-self: flex-end;
}

1 个答案:

答案 0 :(得分:6)

align-self仅适用于flex父级的直接子元素,因此:

  • .service设为display: flex并设为flex-wrap: wrap

  • 使用margin: 0 auto

  • 将按钮居中

工作示例

另外available as a Codepen.

.services {
  display: flex;
}
.service {
  display: flex;
  flex-wrap: wrap;
}
.button {
  align-self: flex-end;
  margin: 0 auto !important; 
  /* !important used for this example only to override foundation.css*/
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/foundation/5.5.1/css/foundation.min.css" rel="stylesheet"/>

<div class="row services">
  <div class="small-3 panel columns service">
    <i class="fa fa-thumbs-o-up"></i>
    <h3>SUSPENDISSE</h3><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. A, ad?</p>
    <div class="button">Read More</div>
  </div>
  <div class="small-3 panel columns service">
    <i class="fa fa-key"></i>
    <h3>MAECENAS</h3><p>Porro quibusdam nostrum eaque, quasi laudantium delectus quaerat cumque, quos.</p>
    <div class="button">Read More</div>
  </div>
  <div class="small-3 panel columns service">
    <i class="fa fa-flag"></i>
    <h3>ALIQUAM</h3><p>Iste architecto omnis, esse facere quod ratione, officia veritatis fugit.</p>
    <div class="button">Read More</div>
  </div>
  <div class="small-3 panel columns service">
    <i class="fa fa-flask"></i>
    <h3>HABITASSE</h3><p>Ducimus voluptates assumenda, illum adipisci sed quaerat est ipsum nisi.</p>
    <div class="button">Read More</div>
  </div>
</div>