Solved

<div> padding creates scrollbars

Posted on 2004-11-14
7
505 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

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

Suggested Solutions

Title # Comments Views Activity
align Linkedin sign to the right page 5 55
css icomoons will not display on page 14 33
Changing alignment and creating border 6 39
Sort Order Icons on HTML Table 3 35
When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

860 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