I was trying to follow along the flexbox example and my line-height is not working for this problem.
The text should be vertically centered, but it's not. It remains at the top only horizontally centered.
In the code snippet it seems to work fine but just to prove that this is acting strange I will give a picture of what I am seeing.
I tested this in both Chrome and IE but it's not vertically centering.
I did change the sizes in the snippet, but I don't think that'd do it.
.flex-container {
display: flex;
flex-flow: row wrap;
justify-content: space-around;
padding: 0;
margin: 0;
list-style: none;
display: -webkit-box;
display: moz-box;
display: -ms-flexbox;
display: -webkit-flex;
-webkit-flex-flow: row wrap;
}
.flex-item {
background: tomato;
padding: 5px;
width: 50px;
height: 50px;
margin-top: 10px line-height: 50px;
color: white;
font-weight: bold;
font-size: 3em;
text-align: center;
}
<ul class="flex-container">
<li class="flex-item">1</li>
<li class="flex-item">2</li>
<li class="flex-item">3</li>
<li class="flex-item">4</li>
<li class="flex-item">5</li>
<li class="flex-item">6</li>
</ul>
To vertically and horizontally center the text in each flex item, make this adjustment to your code:
.flex-container {
display: flex;
flex-flow: row wrap;
justify-content: space-around;
padding: 0;
margin: 0;
list-style: none;
display: -webkit-box;
display: moz-box;
display: -ms-flexbox;
display: -webkit-flex;
-webkit-flex-flow: row wrap;
}
.flex-item {
display: flex; /* create nested flex container */
justify-content: center; /* center text horizontally */
align-items: center; /* center text vertically */
background: tomato;
padding: 5px;
width: 50px;
height: 50px;
color: white;
font-weight: bold;
font-size: 3em;
}
<ul class="flex-container">
<li class="flex-item">1</li>
<li class="flex-item">2</li>
<li class="flex-item">3</li>
<li class="flex-item">4</li>
<li class="flex-item">5</li>
<li class="flex-item">6</li>
</ul>
For more details see: Flexbox: center horizontally and vertically