I am struggling with making my navbar links the same height and keeping their text vertically centered, especially when they wrap onto multiple lines on a narrow viewport. While I have achieved vertical centering, I am facing difficulties in ensuring that the height of all <a>
elements is consistent. You can take a look at the codepen example provided below for reference...
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>