标准流 + 浮动(一行显示)
定位:给盒子定位位置;
相对:不脱标;(position:relative; /* 相对定位:相对于自己原先得位置来偏移,不脱标 */
/* 偏移量 left,right,top,bottom */)
绝对:脱标;(position:absolute;/* absolute绝对定位:根据上一个有定位的父盒子来偏移,如果说往上都没有定位的盒子,就根据body来偏移。 */
/* 绝对定位的盒子会脱标 */
/* 偏移量 left,right,top,bottom */)
固定:可以把盒子单独放在一个位置不动,(例:我的音乐,联系我们,在代码里)
z-index:1; /* 整数/负数/0:值越大,显示越靠前 */
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
.box1{
/* 大相小绝,子绝父相 :父盒子相对定位,子盒子绝对定位*/
position:relative;
width:1000px;
height:1800px;
border:solid 5px red;
}
.box1 div{
width:200px;
height:200px;
}
.box2{
/* /* position:定位 相对定位,绝对定位,固定定位 */
position:relative; /* 相对定位:相对于自己原先得位置来偏移,不脱标 */
/* 偏移量 left,right,top,bottom */
left:100px; /* /* 左偏移100px; */
top:170px;
background-color:pink;
z-index:1; /* 整数/负数/0:值越大,显示越靠前 */
}
.box3{
position:absolute;/* absolute绝对定位:根据上一个有定位的父盒子来偏移,如果说往上都没有定位的盒子,就根据body来偏移。 */
/* 绝对定位的盒子会脱标 */
/* 偏移量 left,right,top,bottom */
top:100px;
right:200px;
background-color:green;
}
.box4{
/* (固定定位) */
position:fixed;
top: 10px;
right:0;
/* right:20px; */
background-color:skyblue;
}
.box4 div{
width:100px;
height:20px;
border:solid 1px green;
margin:auto;
text-align:center;
line-height:20px;
}
.box7{
position:fixed;
width:500px;
height:50px;
top:10px;
background-color:green;
}
</style>
</head>
<body>
<div class="box1">
<div class="box2"></div>
<div class="box3"></div>
<div class="box4">
<div class="box5">我的音乐</div>
<div class="box6">联系我们</div>
</div>
<div class="box7"></div>
</div>
</body>
</html>
定位:盒子
最新推荐文章于 2024-05-15 08:15:00 发布