/    Sign up×
Community /Pin to ProfileBookmark

sub-table td inherits class from table

hi!

i’m just trying to format a table using the following css:

table.nice td
{
vertical-align: top;
text-align: justify;
border: 1px solid #aaa;
background: #ffd;
padding: 5px;
}

table.nice tr.header td
{
text-align: center;
font-weight: bold;
background: #eec;
}

which pads most table cells and allows me to add a slightly different header row (could use th but then i’d have to get rid of the font-changes, etc that th brings with it). so i’m using this something like:

<table class=”nice”>
<tr class=”header”><td>Name</td><td>Occupation</td></tr>
<tr><td>Rigadon</td><td>Professional Numpty</td></tr>
</table>

my problem is that if one of the cells includes another table then all the cells of this ‘sub-table’ take on the same ‘nice’ style defined for the original table! adding a style to the sub-table doesn’t seem to have any effect either…

this isn’t the behaviour i was expecting though i suppose it does make sense – can anyone point me in the right direction please??

to post a comment
CSS

3 Comments(s)

Copy linkTweet thisAlerts:
@ronaldb66May 27.2004 — This is what inheritance is about. Mind you, only properties that actually do inherit are effected.

I guess the only way is to specifically reset the properties for those cells that shouldn't be effected.

(on a side note: nesting tables? Are you sure?)
Copy linkTweet thisAlerts:
@FangMay 27.2004 — Do the same for the nested table:
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;title&gt;css nested tables&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
&lt;style type="text/css"&gt;
&lt;!--
table.nice td
{
vertical-align: top;
text-align: justify;
border: 1px solid #aaa;
background: #ffd;
padding: 5px;
}

table.nice tr.header td
{
text-align: center;
font-weight: bold;
background: #eec;
}

table.xxxx td {
border: 1px solid red;
background: #9fc;
padding: 1px;
}
table.xxxx tr.header td
{
text-align: center;
font-weight: bold;
background: #ccc;
}
--&gt;
&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;table class="nice"&gt;
&lt;tr class="header"&gt;&lt;td&gt;Name&lt;/td&gt;&lt;td&gt;Occupation&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Rigadon&lt;/td&gt;&lt;td&gt;Professional Numpty&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Rigadon&lt;/td&gt;&lt;td&gt;
&lt;table class="xxxx"&gt;
&lt;tr class="header"&gt;&lt;td&gt;Name&lt;/td&gt;&lt;td&gt;Occupation&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Rigadon&lt;/td&gt;&lt;td&gt;Professional Numpty&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;

Avoid using table, unless you are using tabulated data.
Copy linkTweet thisAlerts:
@rigadonauthorMay 27.2004 — cheers guys - you've both helped alot - no more nested tables for me!
×

Success!

Help @rigadon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...