Thanks
Main Topics
Browse All TopicsHi
I'm trying to create a div with overflow:auto and a with a defined top and bottom margin. This div box should fill the entire browser window except the defined margins(see example here: http://www.dhtmlgoodies.co
Here's a code sample:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html
<HTML>
<HEAD>
<title>Overflow issue</title>
<style type="text/css">
html,body{
width:100%;
height:100%;
margin:0px;
padding:0px;
overflow:hidden;
}
#myContainer{
height:100%;
width:500px;
margin-left:100px;
}
.spacer{
height:200px;
background-color:#0FF;
}
.content{
overflow:auto;
background-color:#F00;
margin-top:100px;
margin-bottom:100px;
}
</style>
</HEAD>
<body>
<div id="myContainer">
<div class="content">
This box should have a bottom margin of 100 pixels and a top margin of 100 pixels. When it's not
enough space for this text, a scrollbar should appear.<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
This is the content<br>
</div>
</div>
</body>
</HTML>
What I can't figure out is how to get the space/margins above and below the red box(100 pixels) and on the same time scrollbar at the right side of it when there's too much content.
I can't set a height for the box either since it should be dynamic, i.e. the height should change when the browser window is resized.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: amebaPosted on 2006-11-29 at 06:25:54ID: 18036907
Hi Batalf,
.body.clie ntHeight-( 100+100)+" px");
I used absolute positioning, and it seems to work in IE6, FF2 and Opera 9, just replace style section:
<style type="text/css">
html,body{
height:100%;
margin:0px;
padding:0px;
overflow:hidden;
}
#myContainer{
height:100%;
width:500px;
margin-left:100px;
}
.content{
overflow:auto;
background-color:#F00;
position:absolute;
top:100px;
bottom:100px;
width:500px;
}
</style>
<!--[if IE 6]>
<style>
.content{
height:expression(document
}
</style>
<![endif]-->