.center {
height: 200px;
border: 3px solid green;
text-align: center;
vertical-align: middle;
}
p {
margin: 0;
padding: 0;
}
<div class="center">
<p>I am vertically and horizontally centered.</p>
<p>I am vertically and horizontally centered.</p>
</div>
如何使线条垂直居中?
发布于 2018-06-04 08:01:25
Flexbox解决方案:
.center {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
border: 3px solid green;
height: 200px;
}
p {
margin: 0;
padding: 0;
}
<div class="center">
<p>I am vertically and horizontally centered.</p>
<p>I am vertically and horizontally centered.</p>
</div>
发布于 2018-06-04 09:43:56
你可以用display: flex
:
.center {
height: 200px;
border: 3px solid green;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center
}
p {
border: 1px solid red;
margin: 0;
padding: 0;
}
<div class="center">
<p>I am vertically and horizontally centered. </p>
<p>I am vertically and horizontally centered. </p>
</div>
https://stackoverflow.com/questions/-100004715
复制相似问题