HTML四种定位-固定定位

40 篇文章 0 订阅

固定定位

1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <meta http-equiv="X-UA-Compatible" content="IE=edge">
 6     <meta name="viewport" content="width=device-width, initial-scale=1.0">
 7     <title>Document</title>
 8     <style>
 9         body{
10             height: 2000px;
11         }
12         .box1{
13             width: 200px;
14             height: 200px;
15             background-color: #bfa;
16            
17         }
18         .box2{
19             width: 200px;
20             height: 200px;
21             background-color: tomato;
22            /* 
23              固定定位:
24                -将元素的position属性设置为fixed则开启了元素的固定定位
25                -固定定位也是一种绝对定位,所以固定定位的大部分特点都和绝对定位一样
26                -唯一不同的是固定定位永远参照于浏览器的视口进行定位
27                  固定定位的元素不会随网页的滚动条滚动
28            */
29          position: fixed;
30          left: 200px;
31          top: 200px;
32         }
33         .box3{
34             width: 200px;
35             height: 200px;
36             background-color: greenyellow;
37            
38         }
39         .box4{
40             width: 400px;
41             height: 400px;
42             background-color: rgb(47, 61, 255);
43           
44         }
45         .box5{
46             width: 300px;
47             height: 300px;
48             background-color: rgb(201, 14, 145);
49          
50            
51         }
52     </style>
53 </head>
54 <body>
55     <div class="box1">1</div>
56     <div class="box4">
57         4
58         <div class="box5">
59             5
60             <div class="box2">2</div>
61         </div>
62     </div>
63     
64     <div class="box3">3</div>
65 </body>
66 </html>
固定定位也是一种绝对定位

固定定位永远参照于浏览器的视口进行定位
 固定定位的元素不会随网页的滚动条滚动

固定定位也是一种绝对定位

固定定位永远参照于浏览器的视口进行定位

 固定定位的元素不会随网页的滚动条滚动

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

短暂又灿烂的

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值