css中垂直居中的方式你晓得几种呢?
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">#写css时会遇到<span style="color: black;">非常多</span>垂直居中样式,<span style="color: black;">区别</span>的方式<span style="color: black;">亦</span>会达到<span style="color: black;">一样</span>的效果,以下方式可供参考。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">如让<p> 在 <div>中垂直居中,其中div 标签的宽度、高度分别是400px, 1px的实线边框; p标签背景色是红色。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><div class="box">
<p>hello everyone</p>
</div></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">办法</span>一 :grid布局<span style="color: black;">重视</span>浏览器<span style="color: black;">是不是</span>支持<span style="color: black;">运用</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><style>
.box {
width: 400px;
height: 400px;
border: 1px solid ;
display: grid;
justify-content: center;
align-items: center;
}
p {
bac<span style="color: black;">公斤</span>round: red;
}</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">办法</span>二</p>
<div style="color: black; text-align: left; margin-bottom: 10px;">.box {
width: 400px;
height: 400px;
border: 1px solid ;
display: grid;
justify-content: center;
align-content: center;
}
p {
bac<span style="color: black;">公斤</span>round: red;
}</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">办法</span>三 </p>
<div style="color: black; text-align: left; margin-bottom: 10px;">.box {
width: 400px;
height: 400px;
border: 1px solid ;
display: grid;
}
p {
bac<span style="color: black;">公斤</span>round: red;
margin: auto;
}</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">办法</span>四</p>
<div style="color: black; text-align: left; margin-bottom: 10px;">.box {
width: 400px;
height: 400px;
border: 1px solid ;
display: flex;
}
p {
bac<span style="color: black;">公斤</span>round: red;
margin: auto;
}</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">办法</span>五 :常用方式</p>
<div style="color: black; text-align: left; margin-bottom: 10px;">.box {
width: 400px;
height: 400px;
border: 1px solid ;
display: flex;
justify-content: center;
align-items: center;
}
p {
bac<span style="color: black;">公斤</span>round: red;
}</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">办法</span>六:p<span style="color: black;">必要</span>是inline或是line-block状态</p>
<div style="color: black; text-align: left; margin-bottom: 10px;">.box {
width: 400px;
height: 400px;
border: 1px solid ;
display: table-cell;
vertical-align: middle;
text-align: center;
}
p {
bac<span style="color: black;">公斤</span>round: red;
display: inline-block;
}</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">办法</span>七:margin<span style="color: black;">必要</span>设为0,绝对定位是元素的外边距相对参考元素的边框内壁</p>
<div style="color: black; text-align: left; margin-bottom: 10px;">.box {
width: 400px;
height: 400px;
border: 1px solid ;
position: relative;
}
p {
bac<span style="color: black;">公斤</span>round: red;
position :absolute;
top: 50%;
left: 50%;
transform: translate(-50% ,-50%);
margin: 0;
}</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">办法</span>八: 空标签的line-height的值<span style="color: black;">必要</span>与父元素的值相同</p>
<div style="color: black; text-align: left; margin-bottom: 10px;">.box {
width: 400px;
height: 400px;
border: 1px solid ;
text-align: center;
}
.box::after {
content: ;
line-height: 400px;
}
p {
bac<span style="color: black;">公斤</span>round: red;
display: inline-block;
}</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">办法</span>九:此<span style="color: black;">办法</span><span style="color: black;">必要</span>设置p元素的宽高,否则充满父元素 (此<span style="color: black;">办法</span>已废弃不<span style="color: black;">意见</span><span style="color: black;">运用</span>)</p>
<div style="color: black; text-align: left; margin-bottom: 10px;">.box {
width: 400px</div>
我完全同意你的观点,说得太对了。 回顾历史,我们不难发现:无数先辈用鲜血和生命铺就了中华民族复兴的康庄大道。 这篇文章真的让我受益匪浅,外链发布感谢分享! 大势所趋,用于讽刺一些制作目的就是为了跟风玩梗,博取眼球的作品。
页:
[1]