CSS定位
定位模式:
边偏移:
静态定位(了解):
相对定位(重要):
.box1{
position: relative;
top: 50px;
bottom: 50px;
left: 50px;
right: 50px;
width: 100px;
height: 100px;
background-color: yellow;
}
绝地定位(重要)
.father{
position: relative;
width: 500px;
height: 500px;
background-color: yellow;
}
.son{
position:absolute;
top:10px;
bottom: 10px;
left: 100px;
right: 200px;
width: 100px;
height: 100px;
background-color: pink;
}
子绝父相:子类用绝对定位,父类用相对定位。
案例:
<style>
.father {
position: relative;
float: left;
width: 250px;
height: 200px;
}
.father em {
position:absolute;
top: 4px;
right: 13px;
}
</style>
</head>
<body>
<div class="father">
<div class="pic">
<img src="images/pic.png" alt="">
</div>
<em>
<img src="images/hot.png" alt="">
</em>
</div>
</body>
4.固定定位
固定定位在版心右侧小技巧
<style>
.w{
width: 1000px;
height: 1000px;
background-color: yellow;
margin: 0 auto;
}
.fixed{
position: fixed;
bottom: 5px;
left: 50%;
margin-left: 505px;
width: 100px;
height: 100px;
background-color: pink;
}
</style>
</head>
<body>
<div class="fixed"> 固定内容</div>
<div class="w">版心内容</div>
</body>
5.粘性定位(了解)