2

I have multiple tables on my website.

They are each styled by the following CSS:

#content table { border: 3px solid #FFF; }
#content table tr th { color: #FFF; background-color: #2a2d32; font-size:12px;}
#content table tr td, #content table tr th { border: 1px solid #FFF; padding: 5px; text-align: center; line-height: 1.4em; font-size:12px;}

However I wish to single out a particular table for unique styling The table in question is here:

<table cellspacing="0" cellpadding="0" width="100%" >
<tr style="background-color:#ebe7e5;">
<td>Income </td>
<td>€ </td>
<td>€ </td>
</tr>
<tr class="PL">
<td>Sales</td>
<td><?php echo $cBalance; ?>3,549</td>
<td></td>
</tr>
<th><strong>Total Income</strong></th>
<th></td>
<th><?php echo $pProductionCapacity; ?>3,705</th>
</tr>

<tr style="background-color:#ebe7e5;">
<td>Expenses </td>
<td>€ </td>
<td>€ </td>
</tr>
</table>

I have tried putting an id on this table and then trying CSS, however it seems the main CSS (as shown above) still overrides my changes. Can someone please help?

For example I have added:

<table id="unique" cellspacing="0" cellpadding="0" width="100%" >

With CSS as follows:

#unique td th {background-color: red;}

But it's not working.

/////////////////////////////////////////////////////////////////////////////////

Ok so I have tried changing to:

#unique td {background-color: red;}
#unique th {background-color: red;}

However the th is not changing red, it is still the grey colour from the intial CSS:

#content table { border: 3px solid #FFF; }
#content table tr th { color: #FFF; background-color: #2a2d32; font-size:12px;}
#content table tr td, #content table tr th { border: 1px solid #FFF; padding: 5px; text-align: center; line-height: 1.4em; font-size:12px;}
3
  • did you try table #unique td th {background-color: red;} Commented Feb 2, 2012 at 14:54
  • Can you put all your CSS code? Commented Feb 2, 2012 at 15:19
  • Why? The problem has been solved below Commented Feb 2, 2012 at 15:21

3 Answers 3

6

#unique td th means: "every th inside a td inside #unique". If you mean "every td and also every th inside #unique", what you need is #unique td, #unique th

Sign up to request clarification or add additional context in comments.

1 Comment

It can be... if you have nested tables.
2

Because you have been so specific with your selectors for all the tables you may have to be even more specific for your unique table like this:

#content table#unique tr td, #content table#unique tr th { ... }

Really the table in your selector is redundant as a tr, td and th are always in a table. You could make your selectors simpler by doing:

#content th, #content td { ... }

and then your unique table would be:

#content #unique th, #content #unique td { ... }

Edit

Here's a jsfiddle of what I mean http://jsfiddle.net/BNV22/

You either need to lose the unnecessary table tr from your selectors or you need to keep the selectors the same but add table#unique to the rules that you want to apply to your unique table.

2 Comments

In your edit you haven't done what I suggested you do. That's why it still doesn't work.
Thank you that has fixed everything, if I could give two accepted answers I would!
0

You could use #content table#unique , and you have to put this code after the #content table rule

or you could simple omit the #content for your normal tables

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.