Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS keep 100vh working accurate with padding [duplicate]

I'm using a CSS class that sets the height to the full viewport height using:

.fullheight { min-height: 100vh }

However, there is a nav bar on the top of my page, and I want to preserve space for it using padding

.padding { padding-top: 55px }

Now, I format my div like this:

<div class="fullheight padding"> </div>

The padding works fine, but the height of the div of course is now 55px bigger than my viewport. Since I use different paddings (depending on the shape of the nav bar), I'm looking for a solution that keeps the total height of the div at 100vh, regardless of the padding I add using an additional class. Possible?

like image 817
Jörg Krause Avatar asked Dec 24 '22 21:12

Jörg Krause


1 Answers

You need to use box-sizing: border-box to include padding in the total height of the div. So your code will look like this:

HTML:

<div class="fullheight padding"> </div>

CSS:

.fullheight {
  min-height:         55px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing:    border-box;
  -ms-box-sizing:     border-box;
  -o-box-sizing:      border-box;
  box-sizing:         border-box;
}

.padding {
  padding-top: 55px;
}
like image 135
Wais Kamal Avatar answered Feb 11 '23 12:02

Wais Kamal