Solved

<div> padding creates scrollbars

Posted on 2004-11-14
7
508 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
[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
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
Industry Leaders: 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

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.

Question has a verified solution.

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

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…
When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
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 …
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
Suggested Courses

623 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