Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two divs bottom div to height adjust with browser window [duplicate]

Tags:

html

css

resize

I have a header div and a div underneath it. I need the div underneath the header div to adjust depending on the height of the browser window size.

In CSS, when I add height:100% it creates a scroll bar at the side of the page. When I adjust the percentage of the width, spacing at the bottom of the page constantly changes because it is done with percentages.

I would like the div below the header to always adjust with the window size in height with no spacing at the bottom.

How do I do this?

Here is the Fiddle

JS Fiddle I am not sure why but in JSFiddle the bottom div is not extending height: 100%

here is the code: HTML

 <div class = "main">
  Header
 </div>
 <div class="left">
  Bottom Div
 </div>

CSS

.main {
width:100%;
height:60px;
border: solid;
}

.left {
height: 100%;
width: 300px;
border:solid;
}
like image 986
user3173447 Avatar asked Jul 28 '14 14:07

user3173447


People also ask

How do I keep two divs the same height?

The two or more different div of same height can be put side-by-side using CSS. Use CSS property to set the height and width of div and use display property to place div in side-by-side format. The used display property are listed below: display:table; This property is used for elements (div) which behaves like table.

How do I keep my div from moving when I resize windows?

first add a parent div/wrap and put those two divs of yours into it. Overall, whatever size you add to the min-width itll scale the parent div down to the size specified. once the window is sized down past your specified size, itll behave like any other window. this is my way of doing it.

How do I make a div fit the height of my screen?

Syntax: To set a div element height to 100% of the browser window, it can simply use the following property of CSS: height:100vh; Example: HTML.

How do you make div width and height auto adjust to content?

Syntax: height: length|percentage|auto|initial|inherit; Property Values: height: auto; It is used to set height property to its default value.


1 Answers

try to use something like this code

html:

<div class = "main">
     Header
</div>
<div class="left">
    Bottom Div
</div>

css:

* {
    -webkit-box-sizing:border-box;
    -moz-box-sizing:border-box;
    box-sizing:border-box; 
}
html, body {
    height:100%;
} 
body {
    padding:60px 0 0 0; /* 60 — header height*/
    margin:0;
}
.main,
.left {
    border:1px solid #000;
}
.main {
    width:100%;
    height:60px;
    margin-top: -60px;  /* 60 — header height*/
}

.left {
    height: 100%;
    width: 300px;
}
like image 127
lehi_net Avatar answered Sep 20 '22 07:09

lehi_net