一、块元素
1.子绝父相posolute:relative; posolue:absolute
2.如果是水平居中 则设置left:50% 再设置margin-left:-(width/2)px;
3.如果是垂直居中 则设置top:50% 在设置margin-top:-height/2
4.直接相对于父元素margin:auto;
二、行内元素
1.text-align:center line-height:height
一、块元素
1.子绝父相posolute:relative; posolue:absolute
2.如果是水平居中 则设置left:50% 再设置margin-left:-(width/2)px;
3.如果是垂直居中 则设置top:50% 在设置margin-top:-height/2
4.直接相对于父元素margin:auto;
二、行内元素
1.text-align:center line-height:height
本文标题:盒子中的元素居中的几种情况
本文链接:https://www.haomeiwen.com/subject/vtnciftx.html
网友评论