Solved

CSS: Document Type Adds Extra Padding

Posted on 2011-03-14
3
295 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
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 style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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…

706 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

21 Experts available now in Live!

Get 1:1 Help Now