<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Top and Bottom Halves</title>
<style type="text/css">
* { margin: 0; padding: 0; }
p { padding: 20px; }
#top { background: #eee; }
#bottom { background: #ddd; }
</style>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load("jquery", "1.3.2");
</script><script type="text/javascript">
$(function(){
var $window = $(window);
winHeight = $window.height();
$("#top").height(winHeight/2);
$("#bottom").height(winHeight/2);
$(window).resize(function(){
winHeight = $window.height();
$("#top").height(winHeight/2);
$("#bottom").height(winHeight/2);
});
});
</script>
</head>
<body>
<div id="top">
<p>Top Half</p>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
</div>
<div id="bottom">
<p>Bottom Half</p>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
</div>
</body>
</html>
Top & Bottom Halves Layout
Chris Coyier
on
Thanks Chris! This is exactly what I needed, and I just happened to stumble upon it :)
Why not use CSS solution? :)
html,body{height:100%;}
#top,#bottom{height:50%;}
I was thinking the same thing, but I think it’s because of older browsers not rendering the height property properly or at all.
The best, then, might be both. The Javascript is lean enough that it shouldn’t impact performance, so there’s no problem keeping it, and the CSS’ll be there for those with a newer browser and Javascript off.
Hi really thanks…
It helped me to have the Equal height Column just update function –
* { margin: 0; padding: 0; }
p { padding: 20px; }
.cnt{ height:300px; background:#6666FF;}
#top { background: #eee; width: 49.89%; float: left; }
#bottom { background: #ddd; width: 50%; float: left; }
$(function(){
var $window = $(window);
winHeight = $window.height();
$(“#top”).height(winHeight -300);
$(“#bottom”).height(winHeight -300);
$(window).resize(function(){
winHeight = $window.height();
$(“#top”).height(winHeight-300);
$(“#bottom”).height(winHeight-300);
});
});
— winHeight-300 — Where 300 is the header height of the site
Hello Brother
Top Half
Bottom Half
Hope this will be helpful… :)
Thanks
could you show demo from net that will be easy for view the output
thanks could you allow to see the demo