当前位置:  首页>> 技术小册>> Web响应式布局入门到实战

flex-wrap作用:子元素在父元素盒子中是否换行(列)

属性值 作用
nowrap 默认值,不换行或不换列
wrap 换行或换列
wrap-reverse 换行或换行,但以相反的顺序

示例:
父元素宽度不够,设置子元素自动换行。

  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. #div0{
  10. width:300px;
  11. background-color: violet;
  12. /* 父元素flex布局 */
  13. display:flex;
  14. flex-wrap: wrap;
  15. }
  16. #div0 div{
  17. width: 100px;
  18. height: 100px;
  19. background-color: yellow;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <div id="div0">
  25. <div>1</div>
  26. <div>2</div>
  27. <div>3</div>
  28. <div>4</div>
  29. </div>
  30. </body>
  31. </html>


该分类下的相关小册推荐: