为什么加了top: 0; left: 0; bottom: 0; right: 0; 才能居中?不加就在容器左上方显示? 20
<!DOCTYPEhtml><html><head><title>123</title><styletype="text/css">.parent{width:800px...
<!DOCTYPE html>
<html>
<head>
<title>123</title>
<style type="text/css">
.parent {
width:800px;
height:500px;
border:2px solid #000;
position:relative;
}
.child {
width:200px;
height:200px;
margin: auto;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
background-color: red;
}
</style>
</head>
<body>
<div class="parent">
<div class="child"></div>
</div>
</body>
</html>
margin: auto; 不是居中了吗?
为什么还要再后面加top: 0; left: 0; bottom: 0; right: 0; 展开
<html>
<head>
<title>123</title>
<style type="text/css">
.parent {
width:800px;
height:500px;
border:2px solid #000;
position:relative;
}
.child {
width:200px;
height:200px;
margin: auto;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
background-color: red;
}
</style>
</head>
<body>
<div class="parent">
<div class="child"></div>
</div>
</body>
</html>
margin: auto; 不是居中了吗?
为什么还要再后面加top: 0; left: 0; bottom: 0; right: 0; 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询