Div居中的几种方法,Div absolute居中
程序员文章站
2022-05-01 17:19:59
...
<div></div>
// position: relative 居中
div{
width: 100px;
height: 100px;
margin: 0 auto;
background-color: blue;
}
// position: absolute 居中
div{
width: 100px;
height: 100px;
position: absolute;
left: 50%;
margin-left: -50px;
text-align: center;
background-color: blue;
}