Bor*_*rja 3 html css css3 flexbox
我有两个div(一个在另一个下),并且我希望此列居中对齐。但是使用justify-content: centerdiv是沿y轴居中对齐(垂直),而不是沿x轴居中对齐(水平)。
我想知道是否唯一的方法(使用flexbox)也要沿x轴居中对齐是add margin: auto。
<div id="sharesocial">
<div id="sharecondividi">
Condividi
</div>
<div id="shareicons">
<a target="blank" href=""><span class="fa fa-twitter-square" id="twitterbt"></span></a>
<a target="blank" href=""><span class="fa fa-google-plus-square" id="googleplusbt"></span></a>
<a target="blank" href=""><span class="fa fa-facebook-square" id="facebookbt"></span></a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
的CSS
#sharesocial {
background: #646464 none repeat scroll 0 0;
border-radius: 10px;
display: flex;
flex-direction: column;
height: 100px;
justify-content: center;
width: 174px;
}
#sharecondividi {
align-self: center;
color: #fff;
display: flex;
text-align: center;
}
#shareicons {
align-items: center;
background: #f0f0f0 none repeat scroll 0 0;
border-radius: 5px;
display: flex;
height: 50%;
justify-content: space-around;
width: 95%;
}
Run Code Online (Sandbox Code Playgroud)
这里jsfiddle:
当flex-direction是时column,可以justify-content用于垂直对齐和align-items水平对齐。
尝试这个:
#sharesocial {
align-items: center;
}
Run Code Online (Sandbox Code Playgroud)
学到更多:
| 归档时间: |
|
| 查看次数: |
5766 次 |
| 最近记录: |