Blogger Information
Blog 14
fans 2
comment 2
visits 6709
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
网站定位元素的使用场景与演示
西门瑶雪
Original
384 people have browsed it

网站定位元素的使用场景与演示

定位元素的相互作用

1、定位三个术语:定位元素,最初包含块(定位上下文),参照物
2、固定定位永远相对于视口定位-适用于滚动式永远不变,如回到顶部按钮,在线客服悬浮按钮;
3、绝对定位一直向上找父级-定位父级(定位上下文),不在文档流中;
4、相对定位:自身,在文档流中;
5、粘性定位:sticky,可指定内容滚动悬浮显示

效果图展示

效果图展示

css样式演示

  1. <style>
  2. .box {
  3. border: 1px solid #333;}
  4. .box.dd {width:400px;
  5. height:400px;
  6. background-color: rgb(181, 181, 207);
  7. }
  8. .box.de{height:100px;}
  9. /*默认起始坐标为0,0;top,left,right,bottom;默认0不需要加单位*/
  10. .box.de.da1{background-color: blueviolet;
  11. position: relative;
  12. top: 40px;
  13. left: 20px;
  14. z-index: 1;
  15. }
  16. .box.de.da2{background-color: rgb(24, 136, 180);
  17. position: absolute;
  18. right: 0;
  19. bottom: 0;}
  20. .box.de.da3{background-color: rgb(199, 170, 39);
  21. position:fixed;
  22. right: 100px;
  23. bottom: 50px;
  24. }
  25. body{height: 20000px;
  26. border: 5px solid blue;
  27. height: 500px;}
  28. .box.de.da4{background-color: rgb(226, 120, 21);
  29. position:fixed;
  30. right: 100px;
  31. bottom: 250px;
  32. }
  33. </style>

html代码展示

  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. </head>
  9. <body>
  10. <!--
  11. 1、定位三个术语:定位元素,最初包含块(定位上下文),参照物
  12. 2、固定定位永远相对于视口定位-适用于滚动式永远不变;
  13. 3、绝对定位一直向上找父级-定位父级(定位上下文),不在文档流中;
  14. 4、相对定位:自身,在文档流中;
  15. -->
  16. <div class="box dd">
  17. <div class="box de da1">云逸网-相对定位1</div>
  18. <div class="box de da2">云逸网-绝对定位2</div>
  19. <div class="box de da3">云逸网-固定定位3</div>
  20. <div class="box de da4">云逸网-固定定位4<br>云逸网-固定定位4</div>
  21. <div class="box de da4">云逸网-固定定位4</div>
  22. <div class="box de da4">云逸网-固定定位4</div>
  23. <div class="box de da4">云逸网-固定定位4</div>
  24. <div class="box de da4">云逸网-固定定位4</div>
  25. </div>
  26. <style>
  27. .box {
  28. border: 1px solid #333;}
  29. .box.dd {width:400px;
  30. height:400px;
  31. background-color: rgb(181, 181, 207);
  32. }
  33. .box.de{height:100px;}
  34. /*默认起始坐标为0,0;top,left,right,bottom;默认0不需要加单位*/
  35. .box.de.da1{background-color: blueviolet;
  36. position: relative;
  37. top: 40px;
  38. left: 20px;
  39. z-index: 1;
  40. }
  41. .box.de.da2{background-color: rgb(24, 136, 180);
  42. position: absolute;
  43. right: 0;
  44. bottom: 0;}
  45. .box.de.da3{background-color: rgb(199, 170, 39);
  46. position:fixed;
  47. right: 100px;
  48. bottom: 50px;
  49. }
  50. body{height: 20000px;
  51. border: 5px solid blue;
  52. height: 500px;}
  53. .box.de.da4{background-color: rgb(226, 120, 21);
  54. position:fixed;
  55. right: 100px;
  56. bottom: 250px;
  57. }
  58. </style>
  59. </body>
  60. </html>
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post