如何实现居中对齐
html代码
<div class="vertical">
<div class="content"></div>
</div>
.vertical {
position: relative;
width: 200px;
height: 200px;
margin: 0 auto;
margin-top: 10px;
border: 1px solid blue;
}
.content {
position: absolute;
width: 50px;
height: 50px;
background-color: red;
margin: auto;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
.vertical {
position: relative;
width: 200px;
height: 200px;
line-height: 200px;
margin: 0 auto;
margin-top: 10px;
border: 1px solid blue;
font-size: 0; // 必须设置font-size为0
}
.content {
display: inline-block;
width: 50px;
height: 50px;
background-color: red;
vertical-align: middle;
font-size: 12px;
line-height: 1.2em;
}
.vertical {
display: table-cell;
width: 200px;
height: 200px;
border: 1px solid blue;
vertical-align: middle;
text-align: center;
}
.content {
display: block;
width: 50px;
height: 50px;
margin: 0 auto;
background-color: red;
}
.vertical {
display: flex;
flex-direction: row;
width: 200px;
height: 200px;
border: 1px solid blue;
justify-content: center;
align-items: center;
}
.content {
width: 50px;
height: 50px;
background-color: red;
}