equal-height columns with jquery


/ Published in: jQuery
Save to your folder(s)

equal-height columns


Copy this code and paste it in your HTML
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>CSS Newbie Example: Equal Height Columns with jQuery</title>
  6. <style>
  7. body {
  8. font: small/1.3em Arial, Helvetica, sans-serif;
  9. background-color: white; }
  10. #wrap {
  11. width: 600px;
  12. margin: 0 auto; }
  13. .column {
  14. float: left;
  15. padding: 10px; }
  16. #col1 {
  17. width: 110px;
  18. margin-right: 10px;
  19. background-color: #E2DDC4; }
  20. #col2 {
  21. width: 200px;
  22. margin-right: 10px;
  23. background-color: #6B99F6; }
  24. #col3 {
  25. width: 210px;
  26. background-color: #E87C5E; }
  27. </style>
  28. <script language="javascript" type="text/javascript" src="../../js/jquery/jquery.js"></script>
  29. <script>
  30. function equalHeight(group) {
  31. tallest = 0;
  32. group.each(function() {
  33. thisHeight = $(this).height();
  34. if(thisHeight > tallest) {
  35. tallest = thisHeight;
  36. }
  37. });
  38. group.height(tallest);
  39. }
  40. $(document).ready(function() {
  41. equalHeight($(".column"));
  42. });
  43. </script>
  44. </head>
  45.  
  46. <body>
  47. <div id="wrap">
  48. <h1>Equal Height Columns with jQuery</h1>
  49. <p>This is an example of equal height columns using a single short jQuery function. View the page source or <a href="http://www.cssnewbie.com/equal-height-columns-with-jquery/">refer to the original CSS Newbie article</a> to see how the function works.</p>
  50. <div class="column" id="col1">
  51. <p>This three-column design features three columns with significantly varying quantities of content.</p>
  52. </div>
  53. <div class="column" id="col2">
  54. <p>However, despite the differing quantity amounts, these columns are exactly the same height. No tricks, no gimmicks, no resorting to repeating background images to fake our way to columnar nirvana. And certainly, no tables have been harmed in the making of these columns. </p>
  55. <p>They're simply divs sharing a common class, all of which have been set to the same height.</p>
  56. </div>
  57. <div class="column" id="col3">
  58. <p>And I think a single class is an addition we can all get behind.</p>
  59. </div>
  60. </div>
  61.  
  62. </body>
  63. </html>

URL: http://www.cssnewbie.com/example/equal-heights/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.