J
johkar
The below script sets and maintains the equal heights of 2 (or 3) divs
which are floated next to each other on a page. I want to ensure that
I have not overlooked anything and it will not error. In other words,
it either executes successfully or not at all. This script is a
compilation of code found on various posts along with my
personalization thrown in to meet our specs. Note that this is just a
"nice to have" script so if it doesn't execute the page is still
usable.
John
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<style type="text/css">
div {
border:1px solid #003366;
padding:7px;
width:40%;
float:left;
margin-left:15px;
}
</style>
<script type="text/javascript">
function setDivHeights(id1,id2,id3){
if(document.getElementById){
var div1 =
(document.getElementById(id1))?document.getElementById(id1):false;
var div2 =
(document.getElementById(id2))?document.getElementById(id2):false;
var div3 =
(document.getElementById(id3))?document.getElementById(id3):false;
if(div1 && div2){
var max = div1.offsetHeight;
if(div2.offsetHeight > max)
max = div2.offsetHeight;
if(div3 && (div3.offsetHeight > max))
max = div3.offsetHeight;
document.getElementById(id1).style.height = max + "px";
document.getElementById(id2).style.height = max + "px";
if(div3)
document.getElementById(id3).style.height = max + "px";
}
if(window.onresize)
window.onresize=(div3)?function(){setDivHeights(div1,div2,div3)}:function(){setDivHeights(div1,div2)};
}
}
</script>
</head>
<body onload="setDivHeights('div1','div2')">
<div id="div1">
<p>Some Text Some Text Some Text Some Text Some Text Some Text Some
Text Some Text Some</p>
</div>
<div id="div2">
<p>Some Text Some Text Some Text Some Text Some Text Some Text Some
Text Some Text Some Text Some Text Some Text Some Text Some Text Some
Text Some Text</p>
</div>
</body>
</html>
which are floated next to each other on a page. I want to ensure that
I have not overlooked anything and it will not error. In other words,
it either executes successfully or not at all. This script is a
compilation of code found on various posts along with my
personalization thrown in to meet our specs. Note that this is just a
"nice to have" script so if it doesn't execute the page is still
usable.
John
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<style type="text/css">
div {
border:1px solid #003366;
padding:7px;
width:40%;
float:left;
margin-left:15px;
}
</style>
<script type="text/javascript">
function setDivHeights(id1,id2,id3){
if(document.getElementById){
var div1 =
(document.getElementById(id1))?document.getElementById(id1):false;
var div2 =
(document.getElementById(id2))?document.getElementById(id2):false;
var div3 =
(document.getElementById(id3))?document.getElementById(id3):false;
if(div1 && div2){
var max = div1.offsetHeight;
if(div2.offsetHeight > max)
max = div2.offsetHeight;
if(div3 && (div3.offsetHeight > max))
max = div3.offsetHeight;
document.getElementById(id1).style.height = max + "px";
document.getElementById(id2).style.height = max + "px";
if(div3)
document.getElementById(id3).style.height = max + "px";
}
if(window.onresize)
window.onresize=(div3)?function(){setDivHeights(div1,div2,div3)}:function(){setDivHeights(div1,div2)};
}
}
</script>
</head>
<body onload="setDivHeights('div1','div2')">
<div id="div1">
<p>Some Text Some Text Some Text Some Text Some Text Some Text Some
Text Some Text Some</p>
</div>
<div id="div2">
<p>Some Text Some Text Some Text Some Text Some Text Some Text Some
Text Some Text Some Text Some Text Some Text Some Text Some Text Some
Text Some Text</p>
</div>
</body>
</html>