方法1:
.div1{
width:400px;
height:400px;
border:#CCC 1px solid;
background:#99f;
position:absolute;
left:50%;
top:50%;
transform: translate(-50%,-50%);
}
<div class="div1"></div>
方法2:
.div2{
width:400px;
height:400px;
border:#CCC 1px solid;
background:#99f;
position: absolute;
left:0;
top: 0;
bottom: 0;
right: 0;
margin: auto;
}
<div class="div2"></div>
方法3:
.div3{
width:400px;
height:400px;
border:#CCC 1px solid;
background:#9f9;
position: absolute;
left: 50%;
top:50%;
margin-left:-200px;
margin-top: -200px;
}
<div class="div3"></div>
相关文章:
- div层上下左右居中 2022-12-23
- div页面居中(上下左右) 2021-11-29
- div元素上下左右居中 2021-11-29
- div上下左右居中方法 2021-12-09
- 用CSS让DIV上下左右居中的方法 2021-12-19
- 让DIV在屏幕上下左右居中 - 小豫 2021-12-09
- 如何让图片在div里左右居中,上下居中 2022-12-23
- 小 div在大 div中左右上下居中 2021-11-29