This sort of style and markup will do what you want but can be tricky to design the rest of your page around:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
#cont {
position:absolute;
width:auto;
}
#div1 {
border:1px solid black;
}
</style>
</head>
<body>
<div id="cont">
<div id="div1">Hi</div>
<div id="div2"> </div>
<input type="button" onclick="document.getElementById('div2').innerHTML=document.getElementById('div2').innerHTML.toLowerCase()=='gee golly gosh'? ' ' : 'gee golly gosh';" title="toggle div2 content">
</div>
</body>
</html>
Notes: Click the button to toggle div2's content. You will see div1 expand and contract in some browsers, and in others it will expand but not contract. However, if as you say, the page is loaded fresh each time that div2 gets different content, this wouldn't matter as, div1 only needs to conform onload then, and it will. No javascript is required for this effect. The javascript onclick event for the button is simply to show what happens when the content of div2 is changed.
Bookmarks