height: 100vh; and overflow “content” on smaller screens

前端 未结 2 1143
野趣味
野趣味 2020-12-30 09:07

I have a height: 100vh; but I have a lot of content, which overflows into another \"vh\" on smaller screens, how do I deal w/ the overflow, on smaller screens?<

2条回答
  •  甜味超标
    2020-12-30 09:47

    If I understand correctly, you have multiple elements with height: 100vh, and the problem is that their content may overflow them.

    In that case, you can

    • Use the overflow property to handle overflow correctly.

      For example overflow: auto will add scrollbars only when necessary.

      html,body {
        margin: 0;
      }
      section {
        height: 100vh;
        overflow: auto;
        background: yellow;
      }
      section + section {
        background: lime;
      }
      div {
        height: 150vh;
        margin-left: 15px;
        border-left: 1px dotted;
      }
      Start
      End
      Start
      End

    • Use min-height: 100vh instead of height: 100vh

      This way, if the content is taller, the element will grow to avoid overflow.

      html,body {
        margin: 0;
      }
      section {
        min-height: 100vh;
        background: yellow;
      }
      section + section {
        background: lime;
      }
      div {
        height: 150vh;
        margin-left: 15px;
        border-left: 1px dotted;
      }
      Start
      End
      Start.
      End

提交回复
热议问题