原创

纯css实现瀑布流布局


  瀑布流适合图片多的页面,当然也适合我的速查表页面,这里简单使用css实现一个瀑布流布局。

  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. <style>
  9. * {
  10. padding: 0;
  11. margin: 0;
  12. }
  13. .content {
  14. -moz-column-count: 3;
  15. -webkit-column-count: 3;
  16. column-count: 3;
  17. -moz-column-gap: 1em;
  18. -webkit-column-gap: 1em;
  19. column-gap: 1em;
  20. }
  21. .item {
  22. height: 60px;
  23. padding: 0em;
  24. margin-top: 1em;
  25. -moz-page-break-inside: avoid;
  26. -webkit-column-break-inside: avoid;
  27. break-inside: avoid;
  28. border: 1px solid #000;
  29. background: #909090;
  30. }
  31. .item:first {
  32. margin-top: 0;
  33. }
  34. .h100 {
  35. height: 100px;
  36. }
  37. .h200 {
  38. height: 200px;
  39. }
  40. </style>
  41. </head>
  42. <body>
  43. <div class="content">
  44. <div class="item"></div>
  45. <div class="item"></div>
  46. <div class="item h100"></div>
  47. <div class="item"></div>
  48. <div class="item h200"></div>
  49. <div class="item h100"></div>
  50. <div class="item h100"></div>
  51. <div class="item h100"></div>
  52. <div class="item h100"></div>
  53. <div class="item"></div>
  54. <div class="item"></div>
  55. <div class="item"></div>
  56. <div class="item"></div>
  57. </div>
  58. </body>
  59. </html>

其中请关注3句css

  1. column-count: 4; //想要分割的列数
  2. column-gap: 10%; //每列的边距
  3. break-inside: avoid;
  4. // auto 指定既不强制也不禁止元素内的页/列中断。
  5. // avoid 指定避免元素内的分页符。
  6. // avoid-page 指定避免元素内的分页符。
  7. // avoid-column 指定避免元素内的列中断。
  8. // avoid-region 指定避免元素内的区域中
留言反馈
问题反馈渠道,如有软件无法下载或者其他问题可反馈。【由于某种原因,目前留言不展示】
用户需要登录后才能留言反馈