Solved

CSS: Document Type Adds Extra Padding

Posted on 2011-03-14
3
328 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
[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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

Title # Comments Views Activity
Why a span is lower 2 31
css selector 1 24
Customizing jQuery UI Accordion CSS 3 40
tiled banner 2 13
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…

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