如何让一个div在另一个div中居中

2025-03-05 09:16:50
推荐回答(2个)
回答1:

创建div


    

然后是css中这样写

.parent {
position: relative;
width: 500px;
height: 500px;
border: 1px solid red;
}

.child {
position: absolute;
width: 250px;
height: 250px;
left: 50%;
top: 50%;
margin-left: -125px;
/*设置为宽度(width:250px;)的一半*/
margin-top: -125px;
/*设置为高度(height:250px;)的一半*/
background: #000;
}

回答2:

html中让一个DIV在另一个DIV中水平垂直居中

相关问答
最新问答