绝对定位

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
.box1{
width: 200px;
height: 200px;
background-color: red;
}
.box2{
width: 200px;
height: 200px;
background-color: blue;
/*
* 当position属性值设置为absolute时,则开启了元素的绝对定位
* 绝对定位:
* 1.开启绝对定位,会使元素脱离文档流
* 2.开启绝对定位以后,如果不设置偏移量,则元素的位置不会发生改变
* 3.绝对定位是相对于浏览器窗口进行定位的
* left: 0px;
top: 0px;
可以查看
4.绝对定位是相当于离它最近的 开启了定位的祖先元素进行定位的
一般情况下,开启子元素的绝对定位都会同时开启父元素的相对定位
如果所有的祖先元素都没有开启定位,则会相对于浏览器窗口进行定位
5.绝对定位会使元素提升一个层级
6.绝对定位会改变元素的性质
内联元素会变成块元素
块元素的宽度和高度都被撑开
*/
position:absolute;
left: 0px;
top: 0px;

}
.box3{
width: 500px;
height: 500px;
background-color: aqua;
}
.box4{
width: 400px;
height: 400px;
background-color: black;
/*
* 开启box4绝对定位
*/
position: absolute;

}
.s1{
width: 400px;
height: 400px;
background-color: chartreuse;
position: absolute;

}
</style>
</head>
<body>
<div class="box1"></div>

<div class="box4">
<div class="box2"></div>
</div>

<div class="box3"></div>
<!--内联元素-->
<span class="s1"> wo</span>

</body>
</html>

posted @ 2020-04-09 13:21  Smile*^  阅读(180)  评论(0编辑  收藏  举报