定位:使用口诀:子绝父相 | |
绝对定位 相对定位 固定定位 | |
使用口诀:子绝父相 儿子用绝对定位,父亲用相对定位 | |
共同点:四个值 上右下左 top right bottom left | |
相对定位:依然占有空间,一般不单独使用,开始值从本身的位置开始计算 | |
绝对定位:不占有空间,单独使用的时候是以浏览器作为参考物; | |
如果相对定位存在,那么绝对定位跟随着有相对定位的父亲 | |
-如果是父子关系,那么绝对定位跟随着有相对定位的父亲,兄弟关系跟随浏览器,单独使用跟随者浏览器 |
z-index:层级 值越大越优先显示 | |
使用条件:存在定位 |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
<style type="text/css"> | |
*{ | |
padding:0;margin:0; | |
} | |
div{ | |
width: 200px; | |
height: 200px; | |
background:red; | |
margin:100px 0 0 100px; | |
position:relative; | |
} | |
p{ | |
width: 100px; | |
height: 100px; | |
background:blue; | |
position:absolute; | |
top:20px; | |
left:20px; | |
} | |
</style> | |
</head> | |
<body> | |
<div> | |
<p></p> | |
</div> | |
</body> | |
</html> |