How to Give an Element the Height of the Window

Setting the width of an element to the full window height is done pretty commonly, but it’s a lot more rare for an element to be given the full height of a window. The strategy behind stretching an element to the full height of the window is essentially the same as stretching an element to the full width. In both of these instances, the element will only be able to be as wide or as long as it’s container element, so you have to first make sure that all of the parent elements take up the entire width or height of the window before you can apply the height: 100% to your targeted element.

So for example, let’s say you have a div called .container that you want to have take up the entire height of the window. First, you’ll need to make the html, body, and any other parent elements of .container have a height of 100%:

Join us in our newest publication:
html, body {
  height: 100%;
}

From there it should be easy to stretch the height of all your remaining parent divs until you get to .container:

container{
   height: 100%;
}

Share and Enjoy !

0Shares
0 0