圣杯布局

html 布局

  1. <div class="container">
  2. <div class="item center-box">center</div>
  3. <div class="item left-box">left</div>
  4. <div class="item right-box">right</div>
  5. </div>
html

css 样式

  1. body {
  2. --w100: 100px;
  3. }
  4. .container {
  5. position: relative;
  6. height: 200px;
  7. padding: 0 var(--w100);
  8. }
  9. .container .item {
  10. height: 100%;
  11. float: left;
  12. color: #fff;
  13. font-weight: 600;
  14. font-size: 20px;
  15. }
  16. .container .center-box {
  17. width: 100%;
  18. background-color: blue;
  19. }
  20. .container .left-box {
  21. width: var(--w100);
  22. background-color: pink;
  23. margin-left: -100%;
  24. position: relative;
  25. left: calc(0px - var(--w100));
  26. }
  27. .container .right-box {
  28. width: var(--w100);
  29. background-color: blueviolet;
  30. margin-right: calc(0px - var(--w100));
  31. }
css

效果预览

center
left
right
编程笔记 & 随笔杂谈