麻烦老师检查下
来源:2-4 编程练习
qq__8359
2019-10-29 10:23:52
<!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;
top: 100px;
left: 100px;
}
</style>
</head>
<body>
<div class="per">
<div class="son"></div>
</div>
</body>
</html>
老师,好像给父元素设置的 相对定位 换成 绝对定位 也可以,但是有一点偏移是什么原理?
1回答
同学你好,1. 已完成练习哦~很赞!继续加油!
2. 相对定位是指,该元素相对自己原来位置,偏移一定距离,元素可以通过顶部top,底部bottom,左侧left和右侧right属性来设置定位。它相对的是它自己。
3. 而绝对定位是指,该元素相对它的父元素偏移一定距离,元素可以通过顶部top,底部bottom,左侧left和右侧right属性来设置定位。所以使用不同的定位会有一点偏移。
祝学习愉快!