请问可以用margin实现居中吗?我试了没有作用
来源:2-10 编程练习
Ace_____
2017-07-06 16:15:57
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
/*完善下列代码*/
.per{
width: 300px;
height: 300px;
background: red;
margin-left:200px;
margin-top: 200px;
position: relative;
}
.son{
width: 100px;
height: 100px;
background: blue;
position: absolute;
left: 100px;
top: 100px;
}
</style>
</head>
<body>
<div class="per">
<div class="son"></div>
</div>
</body>
</html>
1回答
在per里面设置 margin:200px auto 0;即可
.per{ width: 300px; height: 300px; background: red; /*margin-left:200px; margin-top: 200px;*/ margin:200px auto 0; position: relative; }
希望可以帮到你!
相似问题