flexbox定位,底部一个顶部的一个项目

时间:2016-10-21 19:27:31

标签: html css flexbox

我有一个有2个物品的容器。 我使用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;
}

1 个答案:

答案 0 :(得分:0)

您可以使用保证金:

.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来查看是否有效或妥协。

相关问题