I am creating a simple menu bar with CSS flexbox. My menu buttons use stretch
so that the buttons are the same height as the menu bar.
The problem is that the text inside the buttons is not centered vertically if one of the divs is taller than the others.
I have tried using align-items:center
and justify-content:center
. While that centers the content, the buttons don't stretch to the same height as their parent anymore, which looks ugly when hovering over the divs :(
Can my flex children stretch vertically AND have their contents centered vertically?
HTML
<nav>
<div><img src="./largelogo.png"></div> // a tall div
<div>Artists</div> // should stretch AND center
<div>Playlists</div>
<div>Genres</div>
</nav>
CSS
nav {
display: flex;
align-items: stretch;
justify-content: center;
background: #60B99A;
color:white;
}
nav div:hover {
color: #60B99A;
background: white;
}