Solved

CSS overflow issue

Posted on 2006-11-29
2
1,275 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 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…

717 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