Top & Bottom Halves Layout

<!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>

Comments

  1. User Avatar
    Andrew
    Permalink to comment#

    Thanks Chris! This is exactly what I needed, and I just happened to stumble upon it :)

  2. User Avatar
    Kartlos Tchavelachvili
    Permalink to comment#

    Why not use CSS solution? :)

    html,body{height:100%;}
    #top,#bottom{height:50%;}

    • User Avatar
      Andrew Champ
      Permalink to comment#

      I was thinking the same thing, but I think it’s because of older browsers not rendering the height property properly or at all.

    • User Avatar
      Michael Schoonmaker
      Permalink to comment#

      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.

  3. User Avatar
    Vipul

    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

  4. User Avatar
    saravanan
    Permalink to comment#

    could you show demo from net that will be easy for view the output

  5. User Avatar
    saravanan
    Permalink to comment#

    thanks could you allow to see the demo

Submit a Comment

Posting Code

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.

icon-anchoricon-closeicon-emailicon-linkicon-logo-staricon-menuicon-nav-guideicon-searchicon-staricon-tag