(一)文字环绕排版
文字环绕图形
shape-outside属性
- margin-box:外边距环绕
- padding-box:内边距环绕
- border-box:边框环绕
- content-box:内容环绕
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> body{ font-size: 32px; } .circle{ width: 200px; height: 200px; border-radius: 50%; border:solid 20px green; background-color: red; display: inline-block; float: left; margin: 20px; padding: 10px; shape-outside: content-box; } </style> </head> <body> <span class="circle"></span> <p>sdssfdfdfkfjslkfsdkclksdjcsldkjcldskjds;dklcdklcmdslkcsdlkcjsdcjdoicjodislkcslkcsdlcksdmlckdsm clksdmcldskcmdlkcmdlckmdlckdmc lksdcmdlkcmsdlckmsdcklmclkscmdslkcmdslkcmdlkcmsdlkc lksdcmdlkcmsdlckmsdcklmclkscmdslkcmdslkcmdlkcmsdlkcm lksdcmdlkcmsdlckmsdcklmclkscmdslkcmdslkcmdlkcmsdlkcm lksdcmdlkcmsdlckmsdcklmclkscmdslkcmdslkcmdlkcmsdlkcm lksdcmdlkcmsdlckmsdcklmclkscmdslkcmdslkcmdlkcmsdlkcm lksdcmdlkcmsdlckmsdcklmclkscmdslkcmdslkcmdlkcmsdlkcmv lksdcmdlkcmsdlckmsdcklmclkscmdslkcmdslkcmdlkcmsdlkcm lksdcmdlkcmsdlckmsdcklmclkscmdslkcmdslkcmdlkcmsdlkcm lksdcmdlkcmsdlckmsdcklmclkscmdslkcmdslkcmdlkcmsdlkcm lksdcmdlkcmsdlckmsdcklmclkscmdslkcmdslkcmdlkcmsdlkcm </p> </body> </html>
clip-path属性:
复制代码
1
2
3
4
5clip-path:circle();//标准画圆 clip-path:(50% at 0 0);//四分之一圆 clip-path:inset(25% 0 round 0 25%);//圆角 clip-path:polygon(0 100%,50% 0,100% 100%);//三角形
整合使用:
复制代码
1
2
3clip-path:circle();//标准画圆 shape-outside:circle();
(二)position属性
position,用于指定元素的定位方式
- static:默认值,文档流标准定位
- relative:相对定位(相对自己原本位置) //不会脱离文档流
- absolute:绝对定位 //脱离文档流
- fixed:固定定位 //相对于浏览器定位
- sticky:粘性定位
位置偏移
top,right,bottom,left:距离上、右、下、左
1.relative
相对定位(相对自己原本位置) //不会脱离文档流
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> .A{ width: 100%; height: 1000px; background-color: green; } .A_1{ width: 100px; height: 100px; background-color: red; position: relative; left: 50px; } .A_2{ width: 100px; height: 100px; background-color: yellow; } </style> </head> <body> <div class="A"> <div class="A_1"></div> <div class="A_2"></div> </div> </body> </html>
2.absolute
脱离文档流,通过指定元素相对于最近的非static定位祖元素的偏移,如果没有则相对于body位置。可以设置外边距(margin),且不会于其他边距合并。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> .A{ width: 100%; height: 300px; background-color: green; margin-top:50px; } .A_1{ width: 100px; height: 100px; background-color: red; position: absolute; top: 0px; } </style> </head> <body> <div class="A"> <div class="A_1"></div> </div> </body> </html>
垂直居中
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> .A{ width: 500px; height: 300px; border: solid 1px #000; position: relative; margin: auto; } .A_1{ width: 100px; height: 100px; background-color: red; position: absolute; /*让左上角定位,然后在相对于自身定位*/ left: 50%; top:50%; transform: translate(-50%,-50%);/*自身的百分比*/ } </style> </head> <body> <div class="A"> <div class="A_1"></div> </div> </body> </html>
3.sticky
相对于父元素
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> .A{ width: 500px; height: 300px; border: solid 1px #000; position: absolute; top:50%; left: 50%; margin: auto; overflow: scroll; } h2{ position: sticky; top: 0; background-color: green; color: #fff; } </style> </head> <body> <div class="A"> <h2>sssssss1</h2> <p>eeeee</p> <h2>sssssss2</h2> <p>eeeee</p> <h2>sssssss3</h2> <p>eeeee</p> <h2>sssssss4</h2> <p>eeeee</p> <h2>sssssss5</h2> <p>eeeee</p> <h2>sssssss6</h2> <p>eeeee</p> <h2>sssssss7</h2> <p>eeeee</p> <h2>sssssss8</h2> <p>eeeee</p> </div> <body> </html>
(三)层次z-index
仅对非z-index的元素生效
值越大优先级越高,父元素不能超越子元素
最后
以上就是故意店员最近收集整理的关于html5学习内容-5(一)文字环绕排版(二)position属性(三)层次z-index的全部内容,更多相关html5学习内容-5(一)文字环绕排版(二)position属性(三)层次z-index内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复