Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CSS overflow issue

Posted on 2006-11-29
2
Medium Priority
?
1,280 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
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…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

636 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