Styling HTML and BODY selector to height: 100%; vs using 100vh

后端 未结 3 409
后悔当初
后悔当初 2020-12-04 11:55

My brother and I were messing around in sublime earlier and he suddenly shout out, \"I learned something new!\"

A little shocked, I asked, \"What\'s that..?\"

<
3条回答
  •  隐瞒了意图╮
    2020-12-04 12:45

    height: 100vh = 100% of the viewport height

    Technically, this is true, but a better way to think of it is = 100% of the available height.

    If you are looking to fill up a div with the available height, that's a mighty useful trick. Before I learned this, I would have to ensure every div from html down to the nested div had a height of 100% which can be tedious and error prone. Instead, I now just use height:100vh on the nested item.

    See this gist.run for an example with Bootstrap 4.1:

提交回复
热议问题