深圳市博士通科技有限公司

css-父标签中的子标签默认位置

2016/12/1 8:46:09   阅读:1190    发布者:1190

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
.a{
width: 100px;
height: 100px;
background: red;
position: relative;
top: 40px;
left: 50px;
padding: 30px;
}
.b{
width: 50px;
height: 50px;
background: bisque;
position: absolute;
}
</style>
</head>
<body>
<div class="a">
<div class="b"></div>
</div>
</body>
</html>

 

 

如果不给b标签设定top和left。他们会有个默认的值。

top和left会以width和height为基础进行定位。