Solved

CSS: Document Type Adds Extra Padding

Posted on 2011-03-14
3
297 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 400 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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
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…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now