?
Solved

CSS overflow issue

Posted on 2006-11-29
2
Medium Priority
?
1,279 Views
Last Modified: 2008-01-09
Hi

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.com/ee/ScreenShot077.png). When content exceeds the "box", a scrollbar should appear at the right side(because of overflow:auto).

Here's a code sample:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<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.
0
Comment
Question by:Batalf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
ameba earned 2000 total points
ID: 18036907
Hi Batalf,
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.body.clientHeight-(100+100)+"px");
   }
   </style>
<![endif]-->
0
 
LVL 32

Author Comment

by:Batalf
ID: 18043845
Thanks
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This article discusses four methods for overlaying images in a container on a web page
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question