Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

<div> padding creates scrollbars

Posted on 2004-11-14
7
Medium Priority
?
511 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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 tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
Suggested Courses

730 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