I am using display: flex
to center an item in its container. It works when I use justify-content
and align-items
(method 1).
In the documentation, all flexbox concepts seem to have both horizontal and vertical versions. However, using flexbox to center items doesn't seem to work when I swap the axes on everything (method 2). What is the asymmetry?
<table>
<tr>
<th>METHOD1</th>
<th>METHOD2</th>
</tr>
<tr>
<td><div class="outer center-method-1"><div class="inner"></div></td>
<td><div class="outer center-method-2"><div class="inner"></div></td>
</tr>
</table>
<style>
table {
border-spacing: 10px;
}
.outer {
background-color: #ddd;
width: 100px;
height: 100px;
}
.inner {
background-color: #f00;
width: 20px;
height: 20px;
}
.center-method-1 {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.center-method-2 {
display: flex;
flex-direction: column;
align-content: center;
justify-items: center;
}
</style>