Reputation: 1601
I am trying to make the blue div expand to the height of the page but nothing seems to work: JSFiddle
css:
/* Reset */
html,body {
width:100%;
height:100%;
margin:0px;
}
/* General */
.clear {
clear:both;
}
/* Page Layout */
#page {
margin-left:250px;
min-height:100%;
background-color:green;
}
#main {
float:right;
width:100%;
background-color:blue;
height:100%;
}
#sidebar {
float:left;
width:250px;
margin-left:-250px;
background-color:#222629;
min-height:100%;
}
and html:
<div id="page">
<div id="main">
main
</div>
<div id="sidebar">
<ul>
<li>something</li>
...
<li>something</li>
</ul>
</div>
<div class="clear"></div>
</div>
The same needs to hold true for the sidebar if the page is much longer than the sidebar content.
Upvotes: 0
Views: 130
Reputation: 2799
function resize () {
var x = $('#page').height();
$('#main').css('height',x+'px');
}
$(document).ready (function(){
resize();
})
$(window).resize(function(){
resize();
})
Upvotes: 0
Reputation: 303
use class expand-panel on both div sidebar and menu.
html, body {
width: 100%;
height: 100%;
margin: 0;
}
.clear {
clear: both;
}
#page {
display: table;
width: 100%;
}
.expand-panel {
display: table-cell;
width: 50%;
}
#main {
background-color: blue;
}
#sidebar {
background-color: #00FF00;
}
Upvotes: 0
Reputation: 7688
Your CSS is correct, but one mistake in your css is, there are lot more content in sidebar which is increasing height of that sidebar. Just put overflow:auto
or overflow-y:auto;
to add a scrollbar to sidebar, which will give you expected result.
Here is complete CSS
/* Reset */
html,body {
width:100%;
height:100%;
margin:0px;
}
/* General */
.clear {
clear:both;
}
/* Page Layout */
#page {
margin-left:250px;
height:100%;
background-color:green;
}
#main {
float:right;
width:100%;
background-color:blue;
height:100%;
overflow:scroll;
}
#sidebar {
float:left;
width:250px;
margin-left:-250px;
background-color:#222629;
max-height:100%;
overflow:scroll;
}
Here is Fiddle.enter link description here
My suggestion is, don't use vm as it doesn't support some browsers and partially support to some. Here is support map
Upvotes: 0
Reputation: 199
/* Reset */
html, body {
width: 100%;
height: 100%;
margin: 0;
}
/* General */
.clear {
clear: both;
}
/* Page Layout */
#page {
display: table;
width: 100%;
}
#main {
width: 50%;
background-color: blue;
display: table-cell;
}
#sidebar {
background-color: #00FF00;
display: table-cell;
background-color: #222629;
}
updated link here
Upvotes: 0
Reputation: 3429
Add this to the bottom of the fiddle, I think its what you want.
#main {
height: 100vh;
}
https://jsfiddle.net/ac1p22r4/
here it is with some extra touchup https://jsfiddle.net/ssj3xtr7/
Upvotes: 1
Reputation: 3358
Just change the height attribute's value of #main and #sidebar like this:
#main, #sidebar {
height: 100vh;
}
This stretches the height of the div to the page's height. Hope this solves your problem.
Upvotes: 0
Reputation: 19341
Because div doesn't contain anything so it will not expanding.
You can give position:fixed
to make blue div to expand to height of page.
#main {
background-color: blue;
float: right;
height: 100%;
position: fixed;
width: 100%;
}
Check: https://jsfiddle.net/qyt83gow/1/
Another option is give min-height
to that div.
Upvotes: 0