Solved

CSS overflow issue

Posted on 2006-11-29
2
1,265 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
2 Comments
 
LVL 15

Accepted Solution

by:
ameba earned 500 total points
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Creating a CSS block that only applies to printing By default, all of your CSS applies to every possible view of your page - whether on screen, printed, landscape, touch-screen, or whatever.  You can, however, add CSS that only applies under certai…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
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 …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now