This question already has answers here:
Center and bottom-align flex items
(3个答案)
两年前关闭。
我有一个装有两件物品的集装箱。
我用flexbox将它们居中,但我希望其中一个在中间,另一个在底部,但他也必须居中。
<section class="primary__section">
    <img class=" primary__section__logo " src=../img/logo_png.png alt=" ">
    <img class=" primary__section__scroll " src=../img/scroll.png alt=" ">
</section>

.primary__section {
    background: url("../img/photo_up.png") no-repeat;
    background-size: cover;
    background-position: 50%;
    min-height: 100vh;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;

&__logo {
    width: 260px;
}

最佳答案

您可以使用保证金:

.primary__section {
    background: url("../img/photo_up.png") no-repeat;
    background-size: cover;
    background-position: 50%;
    min-height: 100vh;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-direction: column;
}
[alt="middle"]{
  margin:auto;
}
[alt=" bottom"] {
  margin:0 auto 0;
}
/* let's test and see where the middle stands */
body {
  margin:0;
  background:linear-gradient(to left, transparent 50%, rgba(0,0,0,0.2) 50%),
    linear-gradient(to top, transparent 50%, rgba(0,0,0,0.2) 50%)
}

<section class="primary__section">
    <img class=" primary__section__logo " src=../img/logo_png.png alt="middle">
    <img class=" primary__section__scroll " src=../img/scroll.png alt=" bottom">
</section>

测试并使用http://codepen.io/gc-nomade/pen/VKqGQm来找出是否有效或是一个好的折衷方案。

关于html - flexbox定位,顶部一项在底部一项,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40184163/

10-10 23:17