03.弹性容器的样式.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. margin: 0;
  11. padding: 0;
  12. list-style: none;
  13. }
  14. ul{
  15. width: 800px;
  16. border: 10px red solid;
  17. /* 设置ul为弹性容器 */
  18. display: flex;
  19. /*
  20. flex-wrap:
  21. 设置弹性元素是否在弹性容器中自动换行
  22. 可选值:
  23. nowrap 默认值,元素不会自动换行
  24. wrap 元素沿着辅轴方向自动换行
  25. wrap-reverse 元素沿着辅轴反方向换行
  26. */
  27. /* flex-wrap: wrap; */
  28. /* flex-wrap: wrap-reverse; */
  29. /* flex-flow wrap 和 direction的简写属性,并且两个值没有顺序要求 */
  30. /* flex-flow: row wrap; */
  31. /*
  32. justify-content
  33. -如何分配主轴上的空白空间(即主轴上的元素如何排列)
  34. -可选值:
  35. flex-start 表示元素沿着主轴的起边排列
  36. flex-end 表示元素沿着主轴的终边排列
  37. center 表示元素居中排列
  38. space-around 空白分布到元素两侧
  39. space-between 空白均匀分布到元素间
  40. space-evenly 空白分布到元素的单侧
  41. */
  42. justify-content: flex-start;
  43. /* justify-content: flex-end; */
  44. /* justify-content: center; */
  45. /* justify-content: space-around; */
  46. /* justify-content: space-evenly; */
  47. /* justify-content: space-between; */
  48. }
  49. li{
  50. width: 200px;
  51. height: 100px;
  52. background-color: #bfa;
  53. font-size: 50px;
  54. text-align: center;
  55. line-height: 100px;
  56. flex-shrink: 0;
  57. }
  58. li:nth-child(2){
  59. background-color: pink;
  60. }
  61. li:nth-child(3){
  62. background-color: orange;
  63. }
  64. </style>
  65. </head>
  66. <body>
  67. <ul>
  68. <li>1</li>
  69. <li>2</li>
  70. <li>3</li>
  71. </ul>
  72. </body>
  73. </html>