Scrolling div without fixed height

前端 未结 3 930
故里飘歌
故里飘歌 2021-02-01 03:44

I need to build a dynamically-resizing scrolling div.

The div should dynamically resize to fit the screen. But if the content doesn\'t fit on the screen, it should disp

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-01 04:28

    Since IE9 you can use viewport units.

    Let's say that the height of your container is dynamic, unless its size is greater than the window height. In that case we stop the expansion & activate the scroll.

    #container{
      background: #eaeaea;
      max-height: 100vh;
      overflow-y: scroll;
    }
    
    div{
      outline: 1px solid orange;
      width: 200px;
      height: 200px;
    }

提交回复
热议问题