Skip to content

Instantly share code, notes, and snippets.

@dei79
Created October 27, 2012 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dei79/3965331 to your computer and use it in GitHub Desktop.
Save dei79/3965331 to your computer and use it in GitHub Desktop.
Ensure two div-elements will get the same height (jquery solution)
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script>
$(function() {
function normalizeHeight($left, $right)
{
// get the max height of the two divs
var $maxHeight = Math.max($left.height(),$right.height())
// get the lower div
var $lowerpanel = $left
if ($lowerpanel.height() > $right.height())
$lowerpanel = $right
// set the height of the lower panel
$lowerpanel.height($maxHeight)
}
normalizeHeight($('#left'), $('#right'))
})
</script>
<style>
#id {
float: left;
}
#left {
float: left;
width: 50%;
background-color: red;
}
#right {
float: left;
width: 50%;
background-color: yellow;
}
</style>
</head>
<body>
<div id="container">
<div id="left">
The left page
</div>
<div id="right">
The right page
<br/>
<br/>
<br/>
with more content
</div>
</div>
</body>
</html>
Copy link

ghost commented Sep 5, 2018

how do we get the higher panel instead of lower panel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment