可以实现内容部分自动撑开,顶部和底部不动

    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. }
    12. /* 不显示滚动条但是可以滚动 */
    13. body::-webkit-scrollbar {
    14. display: none;
    15. }
    16. .container {
    17. /* 给定最小高度,保证不挤压上下部分 */
    18. min-height: 100vh;
    19. display: flex;
    20. flex-direction: column;
    21. }
    22. .container .header {
    23. height: 80px;
    24. background: pink;
    25. }
    26. .container .content {
    27. background-color: skyblue;
    28. flex: 1;
    29. /* content占据所有剩余空间大小 */
    30. }
    31. .container .footer {
    32. height: 60px;
    33. background-color: black;
    34. }
    35. </style>
    36. </head>
    37. <body>
    38. <div class="container">
    39. <div class="header"></div>
    40. <div class="content">
    41. <p>文字</p>
    42. <p>文字</p>
    43. <p>文字</p>
    44. <p>文字</p>
    45. <p>文字</p>
    46. </div>
    47. <div class="footer"></div>
    48. </div>
    49. </body>
    50. </html>

    image.png