我有一個導航欄有一些鏈接,當視口有些狹窄時,它們會纏繞到2+行上。我想將所有導航項目設置爲相同的高度並保持文本垂直居中。到目前爲止,我已經能夠垂直居中所有事物,但我無法獲得所有匹配的<a>'s
的高度。請參考下面codepen例如...Flexbox導航欄,拉伸鏈接是相等的高度
http://codepen.io/anon/pen/GovmZa
.container {
width:950px;
margin:0 auto;
}
ul {
display:flex;
align-items: stretch;
justify-content: flex-start;
}
li {
list-style-type:none;
display:flex;
flex-grow:1;
align-items:center;
flex-direction: column;
text-align:center;
border:1px solid #fff;
text-align:center;
}
a {
color:#fff;
padding:10px;
margin-right:1px;
flex: 1;
display: flex;
align-content: center;
align-items: center;
text-align:center;
background-color:#000;
}
<div class="container">
<p>How do I make the links stretch to be equal heights and keep text vertically aligned in the center?</p>
<ul>
<li>
<a href="#">Can</a>
</li>
<li>
<a href="#">somebody please help me figure</a>
</li>
<li>
<a href="#">this</a>
</li>
<li>
<a href="#">out</a>
</li>
</ul>
</div>
如果這是http://codepen.io/anon/pen/GovmEV你是圖像,我會將它添加爲答案 – CoderPi
試試這個 - http://codepen.io/anon/pen/ZQJKXX?edi tors = 110 – Stickers