定位的分类和应用
一:定位的分类
css定位属性共有三种:
1.相对定位 relative
2. 绝对定位 absolute
3. 固定定位 fixed
二:固定定位
1.固定定位是相对浏览器进行定位,无论页面怎么滚动, 这个盒子显示的位置不变。
2.用途:.网页返回顶部,侧边广告,顶部固定导航条。
3.相关代码:
`<style>
*{
margin: 0;
padding: 0;
}
div{
height: 200px;
background-color: thistle;
}
.nav{
width: 1000px;
height: 50px;
position: fixed;
top: 0;
left: 0;
background-color: tomato;}
4.案例展示代码如下:
<style>
* {
margin: 0;
padding: 0;
}
.y {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 60px;
background-color: #333333;
text-align: center;
}
.x {
width: 1500px;
height: 60px;
margin