1px

  1. .setBorderAll{
  2. position: relative;
  3. &:after{
  4. content:" ";
  5. position:absolute;
  6. top: 0;
  7. left: 0;
  8. width: 200%;
  9. height: 200%;
  10. transform: scale(0.5);
  11. transform-origin: left top;
  12. box-sizing: border-box;
  13. border: 1px solid #E5E5E5;
  14. border-radius: 4px;
  15. }
  16. }

三角形

image.png

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>三角形</title>
  6. <style>
  7. .box {
  8. width: 0px;
  9. height: 0px;
  10. border: 50px solid;
  11. border-color: #1b93fb #1bfb24 #efad48 #ef4848;
  12. }
  13. .triangle {
  14. height: 0;
  15. width: 0;
  16. color: #fff;
  17. }
  18. .bottom {
  19. border-top: 100px solid #000;
  20. border-left: 50px solid transparent;
  21. border-right: 50px solid transparent;
  22. }
  23. .left {
  24. border-right: 100px #000 solid;
  25. border-top: 50px transparent solid;
  26. border-bottom: 50px transparent solid;
  27. }
  28. .right {
  29. border-left: 100px solid #000;
  30. border-top: 50px solid transparent;
  31. border-bottom: 50px solid transparent;
  32. }
  33. .top {
  34. border-bottom: 100px solid #000;
  35. border-left: 50px solid transparent;
  36. border-right: 50px solid transparent;
  37. }
  38. </style>
  39. </head>
  40. <body>
  41. <h3>原理</h3>
  42. <h5>
  43. 如图有四个三角形,将其他三个设为不可见即可实现三角形
  44. </h5>
  45. <div class="box">
  46. </div>
  47. <hr />
  48. <h3></h3>
  49. <div class="triangle bottom"></div>
  50. <hr />
  51. <h3></h3>
  52. <div class="triangle left"></div>
  53. <hr />
  54. <h3></h3>
  55. <div class="triangle right"></div>
  56. <hr />
  57. <h3></h3>
  58. <div class="triangle top"></div>
  59. <hr />
  60. </body>
  61. </html>

三列布局

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>三列水平居中</title>
  6. <style>
  7. * {
  8. padding: 0;
  9. margin: 0;
  10. border: 0;
  11. }
  12. .layout{
  13. height: 100px;
  14. }
  15. .layout .main {
  16. height: 100px;
  17. background: #eee;
  18. }
  19. .layout .left {
  20. width: 300px;
  21. height: 100px;
  22. background: #00B7FF;
  23. }
  24. .layout .right {
  25. width: 100px;
  26. height: 100px;
  27. background: #666;
  28. }
  29. hr {
  30. padding: 12px;
  31. margin-bottom: 12px;
  32. border-bottom: 3px solid #eee;
  33. }
  34. </style>
  35. </head>
  36. <body>
  37. <h2>常见布局</h2>
  38. <h3>左右固定,中间自适应</h3>
  39. <!-- flexbox布局 -->
  40. <h4>1.flexbox布局</h4>
  41. <div class="layout flex">
  42. <style>
  43. .layout.flex {
  44. display: flex;
  45. flex-wrap: nowrap;
  46. }
  47. .flex .main {
  48. flex: 1;
  49. }
  50. </style>
  51. <div class="left">left</div>
  52. <div class="main">
  53. <h2>flex解决方案</h2>
  54. 1.这是三栏布局的浮动解决方案;
  55. 2.这是三栏布局的浮动解决方案;
  56. 3.这是三栏布局的浮动解决方案;
  57. 4.这是三栏布局的浮动解决方案;
  58. 5.这是三栏布局的浮动解决方案;
  59. 6.这是三栏布局的浮动解决方案;
  60. </div>
  61. <div class="right">right</div>
  62. </div>
  63. <hr>
  64. <!-- 绝对定位 -->
  65. <h4>2.绝对定位</h4>
  66. <div class="layout position">
  67. <style>
  68. .layout.position {
  69. position: relative;
  70. }
  71. .position .left {
  72. position: absolute;
  73. top: 0;
  74. left: 0;
  75. }
  76. .position .main {
  77. padding-left: 300px;
  78. padding-right: 100px;
  79. /**
  80. position: absolute;
  81. top: 0;
  82. left: 300px;
  83. right: 100px;
  84. */
  85. }
  86. .position .right {
  87. position: absolute;
  88. top: 0;
  89. right: 0;
  90. }
  91. </style>
  92. <div class="left">left</div>
  93. <div class="main">
  94. <h2>position解决方案</h2>
  95. 1.这是三栏布局的浮动解决方案;
  96. 2.这是三栏布局的浮动解决方案;
  97. 3.这是三栏布局的浮动解决方案;
  98. 4.这是三栏布局的浮动解决方案;
  99. 5.这是三栏布局的浮动解决方案;
  100. 6.这是三栏布局的浮动解决方案;
  101. </div>
  102. <div class="right">right</div>
  103. </div>
  104. <hr>
  105. <!--浮动布局 -->
  106. <h4>3.浮动布局</h4>
  107. <div class="layout float">
  108. <style>
  109. .layout.float {
  110. overflow: hidden;
  111. clear: both;
  112. }
  113. .float .left {
  114. float: left;
  115. }
  116. .float .main {
  117. }
  118. .float .right {
  119. float: right;
  120. }
  121. </style>
  122. <div class="left">left</div>
  123. <div class="right">right</div>
  124. <div class="main">
  125. <h2>float解决方案</h2>
  126. 1.这是三栏布局的浮动解决方案;
  127. 2.这是三栏布局的浮动解决方案;
  128. 3.这是三栏布局的浮动解决方案;
  129. 4.这是三栏布局的浮动解决方案;
  130. 5.这是三栏布局的浮动解决方案;
  131. 6.这是三栏布局的浮动解决方案;
  132. </div>
  133. </div>
  134. <hr>
  135. <!-- 网格布局 -->
  136. <h4>4.网格布局</h4>
  137. <div class="layout grid">
  138. <style>
  139. .layout.grid {
  140. display: grid;
  141. grid-template-rows: 100px;
  142. grid-template-columns: 300px auto 100px;
  143. }
  144. .grid .left {
  145. }
  146. .grid .main {
  147. }
  148. .grid .right {
  149. }
  150. </style>
  151. <div class="left">left</div>
  152. <div class="main">
  153. <h2>grid解决方案</h2>
  154. <code>grid-template-rows: 100px; // 1行,每行高度100px</code>
  155. <br />
  156. <code>grid-template-columns: 300px auto 100px; // 3列,每列宽度300px 自动 100px</code>
  157. <br>
  158. <code>auto</code> 关键字表示由浏览器自己决定长度。
  159. </div>
  160. <div class="right">right</div>
  161. </div>
  162. <hr>
  163. 高度未知的时候,只有flex和table可以使用
  164. <br>
  165. position会脱离文档流,
  166. 高度变化了,为0了
  167. <br>
  168. float会脱离文档流
  169. 内容往左排了
  170. <br>
  171. grid高度需要重新设置
  172. <br>
  173. </body>
  174. </html>