Forum Moderators: not2easy

Message Too Old, No Replies

Padding

nested classes and precedence

         

geoapa

3:27 pm on Aug 8, 2003 (gmt 0)

10+ Year Member



Hey guys, I'm trying to apply a padding of 20 on a <td> tag using css. The problem (I think) is that it does not work because that specific <td> tag inherits the style of the table it's in. It works when I take out the 2 table styles, but is there a way to have both styles there?

I think the td class I created should take precedence. I created another td class to change the background-color and when that is applied it works. Maybe my syntax for the padding style is wrong?


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>test</title>

<style type="text/css">
td.pad20 {padding:20;}
td.red {background-color:red;}

table.blue_border
{width:90%;
border-collapse: collapse;
background-color:#0033CC}

table.blue_border td {padding:1; margin:0; border:none;}

table.gray_table
{width:100%;
border-collapse: collapse;
background-color:#eeeeee}

table.gray_table td {padding:0; margin:0; border:none;}

</style>

</HEAD>
<BODY>

<TABLE class="blue_border">
<TR>
<TD>
<TABLE class="gray_table">
<TR><TD class="red">blah</TD></TR>
<TR><TD class="pad20"><br>blah blah<br></TD></TR>
</TABLE>
</TD>
</TR>
</TABLE>

</BODY>
</HTML>

Ryan8720

3:51 pm on Aug 8, 2003 (gmt 0)

10+ Year Member



You have to specify the measure in either pixels or percent.

padding: 20px;
or
padding: 20%;

If it still doesn't work, try this:

padding: 20px!important;

That tells the browser that the padding should take precedence.

[edited by: Ryan8720 at 6:03 pm (utc) on Aug. 8, 2003]

AWildman

4:33 pm on Aug 8, 2003 (gmt 0)

10+ Year Member



If the prior suggestion doesn't work, make pad20 an id instead of a class (as the id takes precedence over the class) and if THAT doesn't work, put a div with class pad 20 inside the cell that you'd like to have padded.

geoapa

4:37 pm on Aug 8, 2003 (gmt 0)

10+ Year Member



Great, thanks Ryan, the padding:20px!important; worked!

killroy

4:37 pm on Aug 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think the problem is that this:
table.blue_border td
has higher specificity then
td.pad20

Try redefining it as

table.blue_border td.pad20 {padding:20;}

instead, which should have even higher specificity.

SN

geoapa

4:41 pm on Aug 8, 2003 (gmt 0)

10+ Year Member



killroy, that works too! Thanks

And that renders in Dreamweaver as well!

Does anyone know why cell spacing (border-collapse: collapse;) does not render in Dreamweaver? It looks fine in IE.. just curious.

Ryan8720

6:08 pm on Aug 8, 2003 (gmt 0)

10+ Year Member



There should be a space between 20px and!important. For some reason, the editor keeps putting them together.

There are many reasons it may on work in DW: Your settings for DW, you didn't put a necesary ; after collapse, and many more.