博客列表 >定位和五环

定位和五环

心
原创
2020年12月22日 08:38:54804浏览

定位 的本质

  1. 定位属性 position 定位类型分为 静态定位(static) 相对定位(relative);绝对定位(absolute);固定定位(fixed);

  2. 静态定位:position: static 默认的,也就是文档流定位,元素的显示位置与源码顺序一致。

  3. 相对定位: position relative; 相对该元素在文档流的原始位置进行偏移。占用原先的位置来进行定位。

  4. 绝对定位: position absolute;相对于它的祖先中离它最近的”定位元素”的位置发生偏移。会脱离文档流。

  5. 定位元素:只要这个元素中有position: relative;或者position:absolute;就称为定位元素。position:static 不是定位元素。


利用绝对定位做的五环

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>浮动</title>
  7. <style>
  8. * {
  9. padding: 0;
  10. margin: 0;
  11. box-sizing: border-box;
  12. }
  13. .box {
  14. width: 20em;
  15. height: 20em;
  16. border: burlywood solid 2em;
  17. border-radius: 50%;
  18. position: absolute;
  19. }
  20. .box:first-of-type {
  21. border: #0000ff solid 2em;
  22. }
  23. .box:nth-of-type(2) {
  24. border: #000 solid 2em;
  25. left: 20em;
  26. }
  27. .box:nth-of-type(3) {
  28. border: #df0808 solid 2em;
  29. left: 40em;
  30. }
  31. .box:nth-last-of-type(2) {
  32. border: hsl(59, 100%, 50%) solid 2em;
  33. left: 10em;
  34. top: 10em;
  35. }
  36. .box:nth-last-of-type(1) {
  37. border: rgb(94, 255, 0) solid 2em;
  38. left: 30em;
  39. top: 10em;
  40. }
  41. </style>
  42. </head>
  43. <body>
  44. <div class="box"></div>
  45. <div class="box"></div>
  46. <div class="box"></div>
  47. <div class="box"></div>
  48. <div class="box"></div>
  49. </body>
  50. </html>
  • 显示效果
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议