?
Solved

CSS: Document Type Adds Extra Padding

Posted on 2011-03-14
3
Medium Priority
?
342 Views
Last Modified: 2012-05-11
My code validates per W3C standards however there is excessive padding in the table.

When I remove the document type definition, there is no longer excessive padding.  

How can I keep this line and still avoid excessive padding?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>number</title> 
 
<style type="text/css"> 
 
html,body {  
margin:0;  
padding:20px; 
font-family:arial, helvetica, sans-serif;  
}  
 
table.numberTable {  
font-size: 13px;  
padding: 0;
margin: 0;
border-collapse:collapse;
border: 0;
border: 1px solid #999;
}
 
table.numberTable tr {  
padding: 0;
margin: 0;
}
 
table.numberTable td {  
padding: 2px 4px 2px 4px;
margin: 0;
}
  
table.numberTable tr.numberRow1 {
background: #efefef;
border-left: 1px solid #999;
border-right: 1px solid #999;
}
 
table.numberTable tr.numberRow2{
background: #fff;
border-left: 1px solid #999;
border-right: 1px solid #999;
}
 
</style> 
 
</head> 
<body> 
 
<table class="numberTable"> 
<tr class="numberRow2"><td class="date"><p>Mar 10</p></td><td class="teamAway"><p>LA LAkers</p></td><td class="spreadAway"><p></p></td></tr><tr class="numberRow2"><td class="time"><p>4:05</p></td><td class="teamHome"><p>Miami</p></td><td class="spreadHome"><p>+1</p></td></tr><tr class="numberRow2"><td colspan="2" class="Number"><p>Foobar</p></td><td class="total"><p>189</p></td></tr><tr class="numberRow1"><td class="date"><p>Mar 10</p></td><td class="teamAway"><p>New York</p></td><td class="spreadAway"><p>+5</p></td></tr><tr class="numberRow1"><td class="time"><p>6:35</p></td><td class="teamHome"><p>Dallas</p></td><td class="spreadHome"><p></p></td></tr><tr class="numberRow1"><td colspan="2" class="Number"><p>Foobar</p></td><td class="total"><p>217.5</p></td></tr><tr class="numberRow2"><td class="date"><p>Mar 10</p></td><td class="teamAway"><p>Denver</p></td><td class="spreadAway"><p>+3.5</p></td></tr><tr class="numberRow2"><td class="time"><p>7:35</p></td><td class="teamHome"><p>Phoenix</p></td><td class="spreadHome"><p></p></td></tr><tr class="numberRow2"><td colspan="2" class="Number"><p>Foobar</p></td><td class="total"><p>216.5</p></td></tr><tr class="numberRow1"><td class="date"><p>Mar 11</p></td><td class="teamAway"><p>LA Clippers</p></td><td class="spreadAway"><p></p></td></tr><tr class="numberRow1"><td class="time"><p>4:05</p></td><td class="teamHome"><p>New Jersey</p></td><td class="spreadHome"><p>+2.5</p></td></tr><tr class="numberRow1"><td colspan="2" class="Number"><p>Foobar</p></td><td class="total"><p>191.5</p></td></tr><tr class="numberRow2"><td class="date"><p>Mar 11</p></td><td class="teamAway"><p>Boston</p></td><td class="spreadAway"><p></p></td></tr><tr class="numberRow2"><td class="time"><p>4:05</p></td><td class="teamHome"><p>Philadelphia</p></td><td class="spreadHome"><p>+2</p></td></tr><tr class="numberRow2"><td colspan="2" class="Number"><p>Foobar</p></td><td class="total"><p>190</p></td></tr><tr class="numberRow1"><td class="date"><p>Mar 11</p></td><td class="teamAway"><p>Detroit</p></td><td class="spreadAway"><p>+9</p></td></tr><tr class="numberRow1"><td class="time"><p>5:05</p></td><td class="teamHome"><p>Oklahoma City</p></td><td class="spreadHome"><p></p></td></tr><tr class="numberRow1"><td colspan="2" class="Number"><p>Foobar</p></td><td class="total"><p>206.5</p></td></tr><tr class="numberRow2"><td class="date"><p>Mar 11</p></td><td class="teamAway"><p>Sacramento</p></td><td class="spreadAway"><p>+11.5</p></td></tr><tr class="numberRow2"><td class="time"><p>5:35</p></td><td class="teamHome"><p>San Antonio</p></td><td class="spreadHome"><p></p></td></tr><tr class="numberRow2"><td colspan="2" class="Number"><p>Foobar</p></td><td class="total"><p>208</p></td></tr><tr class="numberRow1"><td class="date"><p>Mar 11</p></td><td class="teamAway"><p>Orlando</p></td><td class="spreadAway"><p></p></td></tr><tr class="numberRow1"><td class="time"><p>7:35</p></td><td class="teamHome"><p>Golden State</p></td><td class="spreadHome"><p>+4.5</p></td></tr><tr class="numberRow1"><td colspan="2" class="Number"><p>Foobar</p></td><td class="total"><p>207.5</p></td></tr>
</table> 
 
</body> 
</html>

Open in new window

0
Comment
Question by:hankknight
  • 2
3 Comments
 
LVL 9

Expert Comment

by:sah18
ID: 35129809
I didn't test this with your exact code, but generally speaking, it is wise to zero out these settings before doing anything further:

html, body {
 margin: 0px;
 padding: 0px;
 border: 0px;
 }

Each web browser will apply some level of default padding, margin, and border sizing, and they are all different.  This probably relates to the way the browser is setting things when the DTD is in place.  But, zeroing these out *always* is good practice for compatibility, and let's you start clean each time.  Then, just add back in the sizing that you wish to actually see.

Let me know if this corrects the issue you are having.
0
 
LVL 8

Accepted Solution

by:
imantas earned 1600 total points
ID: 35130052
I think it's not the padding of the table cells, it's the default margin of a 'p' (paragraph) element.

Add this to your CSS:
p { margin: 0px; }

Open in new window

0
 
LVL 9

Assisted Solution

by:sah18
sah18 earned 400 total points
ID: 35131564
This might be overkill, but you can *really* strip out all the defaults across everything, if you wish.  Some web designers swear by this.  Eric Meyer, well-known css guru has a version of this here:

http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/

It's called "reloaded" because he had a reset he'd previously used, but then added a bit more to it for his reloaded version.

You'll need to set many things that you might not normally need to, since this strips out so much, but you will truly have the most control that you can by using something like this.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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…
This is a how to build your own CSS3 slideshow and when I say CSS3 I mean just CSS with no javascript in sight! There a few examples online of how to do this but most just show you an example without any explanation, others make it more complicat…
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…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses
Course of the Month17 days, 8 hours left to enroll

830 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