Blogger Information
Blog 7
fans 0
comment 1
visits 4250
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1026作业: 1. 实例演示BFC的三个作用 2. flex容器常用的四个属性, 并实例演示
Vic
Original
529 people have browsed it

实例演示BFC的三个作用

BFC作用1-代码如下:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. * {
  9. box-sizing: border-box;
  10. }
  11. /* box1 加BFC的情况下,可以包裹住float,使得.box1-box被.box1的实线框给包裹住 */
  12. .box1 {
  13. border: 3px solid;
  14. border-color: blue;
  15. overflow: hidden;
  16. }
  17. .box1-box{
  18. width: 8em;
  19. height: 7em;
  20. background-color: red;
  21. border: 2px solid rgb(14, 6, 13);
  22. float: right;
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <div class="box1">
  28. <div class="box1-box"></div>
  29. </div>
  30. </body>
  31. </html>

BFC作用1-效果如下:


BFC作用2-代码如下:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. .world{
  9. box-sizing: border-box;
  10. border: 2px solid;
  11. }
  12. .box{
  13. overflow: auto;
  14. }
  15. /* BFC在垂直方向上外边距不产生折叠。例如下面.box2-1下边距为5em,.box2-2上边距为5em,则.box2-1与.box2-2实际距离为:10em */
  16. .box2-1{
  17. width: 10em;
  18. height: 5em;
  19. background-color: blue;
  20. margin-bottom: 5em;
  21. }
  22. .box2-2{
  23. width: 10em;
  24. height: 5em;
  25. background-color: blue;
  26. margin-top: 5em;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <div class="world">
  32. <div class="box">
  33. <div class="box2-1"></div>
  34. </div>
  35. <div class="box2-2"></div>
  36. </div>
  37. </body>
  38. </html>

BFC作用2-效果如下:


BFC作用3-代码如下:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. * {
  9. box-sizing: border-box;
  10. }
  11. .box{
  12. border: 2px solid;
  13. }
  14. img{
  15. float: right;
  16. }
  17. p{
  18. overflow: hidden;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <div class="box">
  24. <img src="https://img.php.cn/upload/course/000/000/003/5a699f1b2da2b398.jpg" alt="">
  25. <p>
  26. 今天上午10点,国新办举行新闻发布会,国家统计局发布前三季度国民经济运行情况。
  27. 前三季度,全国居民消费价格同比上涨3.3%,涨幅比上半年回落0.5个百分点。
  28. 其中,城市上涨3.1%,农村上涨4.1%。9月份,全国居民消费价格同比上涨1.7%,
  29. 环比上涨0.2%。分类别看,前三季度食品烟酒价格同比上涨10.9%,衣着下降0.2%,
  30. 居住下降0.3%,生活用品及服务上涨0.1%,交通和通信下降3.5%,教育文化和娱乐上涨1.4%,
  31. 医疗保健上涨1.9%,其他用品和服务上涨5.0%。在食品烟酒价格中,粮食上涨1.2%,鲜菜上涨6.1%;
  32. 猪肉价格上涨82.4%,比上半年回落21.9个百分点。扣除食品和能源价格后的核心CPI上涨0.9%。
  33. (总台央视记者 徐宁宁 都昕竹)
  34. </p>
  35. </div>
  36. </body>
  37. </html>

BFC作用3-效果如下:


flex容器常用的四个属性

代码如下:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. *{
  9. box-sizing: border-box;
  10. }
  11. .box{
  12. width: 40em;
  13. height: 20em;
  14. border: 2px solid;
  15. display: flex;
  16. /* 常用属性1。flex-flow主轴方向与换行方式 */
  17. flex-flow: row wrap;
  18. /* 常用属性2.justify-content项目在主轴上两侧空间平均分配 */
  19. justify-content:space-around;
  20. /* 常用属性3.align-items项目在交叉轴上居中 */
  21. align-items: center;
  22. }
  23. .box > .box1{
  24. width: 8em;
  25. height: 3em;
  26. border: 1px solid;
  27. }
  28. .box2 {
  29. width: 40em;
  30. height: 20em;
  31. border: 2px solid;
  32. display: flex;
  33. /* 主轴方向与换行方式 */
  34. flex-flow: row wrap;
  35. /* 常用属性4.align-content项目在多行容器中的对齐方式 */
  36. align-content: center;
  37. }
  38. .box2 > .box2-1{
  39. width: 8em;
  40. height: 3em;
  41. border: 1px solid;
  42. </style>
  43. </head>
  44. <body>
  45. <div class="box">
  46. <div class="box1">box1</div>
  47. <div class="box1">box2</div>
  48. <div class="box1">box3</div>
  49. <div class="box1">box4</div>
  50. <div class="box1">box5</div>
  51. <div class="box1">box6</div>
  52. <div class="box1">box7</div>
  53. <div class="box1">box8</div>
  54. <div class="box1">box9</div>
  55. <div class="box1">box10</div>
  56. </div>
  57. <hr></hr>
  58. <div class="box2">
  59. <div class="box2-1">box11</div>
  60. <div class="box2-1">box12</div>
  61. <div class="box2-1">box13</div>
  62. <div class="box2-1">box14</div>
  63. <div class="box2-1">box15</div>
  64. <div class="box2-1">box16</div>
  65. <div class="box2-1">box17</div>
  66. <div class="box2-1">box18</div>
  67. <div class="box2-1">box19</div>
  68. <div class="box2-1">box20</div>
  69. </div>
  70. </body>
  71. </html>

效果如下:

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:非常不错
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments