07.盒子的垂直方向布局.html 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. 默认情况下,父元素的高度被内容撑开
  11. */
  12. .outer{
  13. background-color: #bfa;
  14. }
  15. .inner{
  16. width: 100px;
  17. height: 200px;
  18. background-color: yellow;
  19. margin-bottom: 100px;
  20. }
  21. .box1{
  22. width: 200px;
  23. height: 200px;
  24. background-color: #bfa;
  25. overflow: auto;
  26. /*
  27. 子元素是在父元素的内容区中排列的,
  28. 如果子元素的大小超过了父元素,则子元素会从父元素中溢出
  29. 使用 overflow 属性来设置父元素如何处理溢出的子元素
  30. 可选值:
  31. visible:默认值,子元素会从父元素中溢出,在父元素外部的位置显示
  32. hidden:溢出内容将会被裁剪,不会显示
  33. scroll:生成两个滚动条,通过滚动条来查看完整的内容
  34. auto:根据需要生成滚动条
  35. overflow-x:单独处理水平方向的溢出
  36. overflow-y:单独处理垂直方向的溢出
  37. */
  38. }
  39. .box2{
  40. width: 100px;
  41. height: 400px;
  42. background-color: orange;
  43. }
  44. </style>
  45. </head>
  46. <body>
  47. <!-- <div class="outer">
  48. <div class="inner"></div>
  49. <div class="inner"></div>
  50. </div> -->
  51. <div class="box1">
  52. <div class="box2"></div>
  53. </div>
  54. </body>
  55. </html>