HTML
<div class="header">Header</div>
<div class="body">
<table class="body-table">
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
</table>
</div>
<div class="footer">
<button>Submit</button>
</div>
CSS
.header{
height:50px;
background-color:#ccc;
width:500px;
}
.body{
width:500px;
max-height:600px;
text-align:center;
background-color:#ddd;
overflow:auto;
}
.body .body-table{
border-collapse:collapse;
text-align:center;
margin:0 auto;
width:100%;
}
.footer{
width:500px;
height:50px;
background-color:#eee;
}
JQUERY
var windowHeight = $(window).height();
$(window).resize(function(){
if(windowHeight<600+'px'){
$('.body').height($('.body').height()-20+'px');
}
});
JSfiddle
I want to increase and decrease according to resizing window. if window height<600 decrease .body div height or if window height>600 increase. But I can't do it. My jquery code not work how can I do this?
You don't need to add "px". And you should be retrieving the window height after the resize event is triggered.
Your logic is flawed though. With this code, the height of the '.body' will be shrunk down to 0 after enough resize events are triggered.
Try this one. You can assign a range and a specific height for that range
Tried to do it without javascript and added one additional
.container
division:HTML:
CSS:
and here is the full final result: http://jsfiddle.net/bDL46/2/