我有一个导航栏有一些链接,当视口有些狭窄时,它们会缠绕到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