绝对定位

 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 .box1{
10 width: 200px;
11 height: 200px;
12 background-color: #bfa;
13
14 }
15 .box2{
16 width: 200px;
17 height: 200px;
18 background-color: tomato;
19 /* 绝对定位
20
21 --当元素的position设置为absolute
22 -绝对定位的特点:
23 1、开启绝对定位后,如果不设置偏移量,元素的位置不会发生变化
24 2、开启绝对定位后,元素会从文档流中脱离
25 3、绝对定位会改变元素的性质,行内变成块,块的宽高被内容撑开
26 4、绝对定位会使元素提升一个层级
27 5、绝对定位元素是相对于其包含块进行定位的
28
29 包含块(containing block)
30 -正常情况下:
31 包含块就是离当前元素最近的祖先块元素
32 -绝对定位的包含块:
33 包含块就是离他最近的开启了定位的祖先元素
34 如果所有的祖先元素都没有开启定位 则根元素就是它的包含块
35 -html(根元素、初始包含块)
36 */
37 position: absolute;
38 bottom: 0;
39 right: 0;
40 }
41 .box3{
42 width: 200px;
43 height: 200px;
44 background-color: greenyellow;
45
46 }
47 .box4{
48 width: 400px;
49 height: 400px;
50 background-color: rgb(47, 61, 255);
51 position: relative;
52 }
53 .box5{
54 width: 300px;
55 height: 300px;
56 background-color: rgb(201, 14, 145);
57 /* position: relative; */
58
59 }
60 </style>
61 </head>
62 <body>
63 <div class="box1">1</div>
64 <div class="box4">
65 4
66 <div class="box5">
67 5
68 <div class="box2">2</div>
69 </div>
70 </div>
71
72 <div class="box3">3</div>
73 </body>
74 </html>
绝对定位是对于包含块而言的 其祖先元素应设置position:relative;
则会相对于对应已经设置position进行绝对定位,如果都没设置则会对于body,最后相对于HTML,也就是说位于页面的最左上角。


 

最新文章

  1. Azure PowerShell (6) 设置单个Virtual Machine Endpoint
  2. oracle数据库常用查询
  3. EF架构~基于EF数据层的实现
  4. Customer IEnuramble Extension
  5. linux安装rzsz
  6. codevs 2494 Vani和Cl2捉迷藏
  7. css实现居中的各种方法
  8. FTP配置参数
  9. 使用R进行相关性分析
  10. java集合系列——List集合之Stack介绍(五)
  11. MySQL之InnoDB数据页结构(转自掘金小册 MySQL是怎样运行的,版权归作者所有!)
  12. 图数据库-Neo4j使用
  13. Shell 同步时间脚本
  14. 使用html5 Canvas绘制线条(直线、折线等)
  15. 【APP测试(Android)】--安装卸载
  16. Redis简单生产者消费者
  17. UBUNTU下MONGODB出现PHP Fatal error: Uncaught exception &#39;MongoConnectionException&#39; with message 和 Authentication failed on database &#39;admin&#39; with username
  18. 说说自己对hibernate一级、二级、查询、缓存的理解。
  19. Linux top里面%CPU和us%的解释
  20. HDU4686—Arc of Dream

热门文章

  1. Go语言核心36讲(Go语言基础知识五)--学习笔记
  2. 用最简单的方式理解 IoC 控制反转
  3. Web前端安全之安全编码原则
  4. 第6次 Beta Scrum Meeting
  5. BUAA 2020 软件工程 个人博客作业
  6. Noip模拟47 2021.8.25
  7. C# 如何将日期格式化ISO8601模式
  8. 检查是否是BST 牛客网 程序员面试金典 C++ java Python
  9. 2021CCPC河南省赛(部分代码待更)
  10. HTML 罗盘式时钟