Solved

<div> padding creates scrollbars

Posted on 2004-11-14
7
506 Views
Last Modified: 2011-10-03
This code should sum it up, its psuedo code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html>
<head>

<style>
.example {
      padding: 6px;
      background: #BFCFFF;
      width: 100%;
}
</style>

</head>

<body>
<div class="example">
<table style="width:100%">
<tr><td>stuff</td><td>more</td></tr>
</table>

The padding and width 100% on the css example make the scroll bar appear in firefox, and in IE with the DOCTYPE above (dosen't without the DOCTYPE).

Any suggestions on what I am doing wrong? How do I make the padding get taken into account the 100%, ie 100%-padding?!
0
Comment
Question by:thepadders
7 Comments
 
LVL 15

Expert Comment

by:Daydreams
ID: 12580529
Hi thepadders,


Try this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<style type="text/css">
body {padding:0;margin:0;}
.example {
     padding: 6px;border:1px red solid;
     background: #BFCFFF;    /* removed the 100% here/*    
}

</style>
</head>
<body>
<div class="example">
<table style="width:100%">
<tr><td>stuff</td><td>more</td></tr>
</table>
</div>
</body>
</html>
0
 

Author Comment

by:thepadders
ID: 12580540
Yeah, that probably will work (it worked when I just removed the 100% for the <div>, but the thing is there will not always be a <table>, ie the div is the container which is meant to be 100% wide - and then we have content in the div, in this case a table which i want to be 100%.
0
 
LVL 10

Expert Comment

by:dij8
ID: 12580755
This seems to work:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style>
.example {
     padding: 6px;
     background: #BFCFFF;
}
.example #fullwidth {
     width: 100%;
}
</style>
</head>
<body>
<div class="example"><table id="fullwidth">
<tr><td>stuff</td><td>more</td></tr>
</table></div>
</body>
</html>

I named the table in case you want to use something else.  You could replace:
.example #fullwidth {
with
.example table {
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:php-webdesign
ID: 12582528
this is a IE bug... try setting the body width just a few pixels smaller
0
 
LVL 15

Accepted Solution

by:
Daydreams earned 500 total points
ID: 12587295
Hi thepadders,

In my example above you don't need the "body {padding:0;margin:0;}" unless you want it.

The div "example" (or any div) has by default a width of 100%. By adding it specifically to that div you get a width of 100% plus the padding, thus the scrolling.
0
 

Author Comment

by:thepadders
ID: 12587475
Thanks, that did it! I realised I had an extra master div set at 100%, I was using that to set the margins instead of the body because the navigation menu is flush to the sides. Removing this 100% fixed it, never realised that DIVS automatically where at 100%. Thanks so much!
0
 
LVL 15

Expert Comment

by:Daydreams
ID: 12587762
You're welcome, thepadders, and thanks for the A:)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DataTables + iCheck + pagination Issue 2 66
Non-Resizable Pharagraph 2 17
ASP.net Markup for Sub Menu 2 39
Word Press Fixes to Google Speed Test Issues 2 17
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…
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
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…
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…

685 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