Solved

CSS overflow issue

Posted on 2006-11-29
2
1,274 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

CSS3 Custom checkboxes This article shows how to style the checkbox form element using only CSS. Works in: Chrome, FF, Safari, Opera, IE9+ Uses modernizr.js to check for :checked pseudo class, falling back to plain old checkboxes (IE8 and bel…
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…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

737 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