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

前端 未结 2 1144
野趣味
野趣味 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:40

    Please try overflow: auto; in the style of the container.

    Sample code

    0 讨论(0)
  • 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;
      }
      <section>
        Start<div></div>End
      </section>
      <section>
        Start<br />End
      </section>

    • 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;
      }
      <section>
        Start<div></div>End
      </section>
      <section>
        Start.<br />End
      </section>

    0 讨论(0)
提交回复
热议问题