Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set div height to fit to the browser using CSS

Tags:

html

css

I have two DIVs inside a container div, where I need to set them both to fit to the browser window like below, but it doesn't fit in my code, please suggest me a solution

enter image description here

My Style Sheet code

 html, body {                 width: 100%;                 height: 100%;                 margin: 0;                 padding: 0;              }  .container {     height: auto;     width: 100%; } .div1 {     float: left;     height: 100%;      width: 25%; } .div2 {     float: left;     height: 100%;     width: 75%; } 

Body

<body> <div class="container">   <div class="div1"></div>   <div class="div2"></div> </div> 

like image 812
Dilukshan Mahendra Avatar asked Sep 21 '13 15:09

Dilukshan Mahendra


People also ask

How do you fit content and height in CSS?

If height: auto; the element will automatically adjust its height to allow its content to be displayed correctly. If height is set to a numeric value (like pixels, (r)em, percentages) then if the content does not fit within the specified height, it will overflow.


1 Answers

You could also use viewport percentages if you don't care about old school IE.

height: 100vh;

like image 176
Dsmart Avatar answered Sep 20 '22 23:09

Dsmart