Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CSS: Document Type Adds Extra Padding

Posted on 2011-03-14
3
Medium Priority
?
336 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 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

CSS3 Custom checkboxes This article shows how to style the checkbox form element using only CSS. Works in: Chrome, FF, Safari, Opera, IE9+ Uses modernizr.js to check for :checked pseudo class, falling back to plain old checkboxes (IE8 and bel…
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 add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
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…
Suggested Courses

636 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