Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css style overwrite order?

Well i have 2 css includes

<link href="Styles/layout.css" rel="stylesheet" type="text/css" />
<link href="Styles/ATJournal.css" rel="stylesheet" type="text/css" />

layout.css

Table.infoBox tr td table tr td
{
    padding: 0px;
    border: 0px;
}

ATJournal.css

table.ATJMainTable tr td
{
    border: 1px solid black;
    padding: 3px;
}

and then we have this table

<Table class="infoBox">
    <tr>
        <td>
        <table class="ATJMainTable">
            <tr>
                <td>
                    some text!
                </td>
            </tr>
        </table>
    </tr>
</table>

Why does layout.css overwrite ATJournal.css in this case?

Even if i change the order of the css includes "layout.css" still overwrites ATJournal.css....

like image 618
Peter Avatar asked May 11 '09 13:05

Peter


3 Answers

The selector is more specific.

Table.infoBox tr td table tr td 

is styling td cells inside a table which is inside a table classed with infobox.

table.ATJMainTable tr td

is styling td cells inside a table classed with ATJMainTable

You could use !important to override the specificity, or you could do something like:

table.infoBox tr td table.ATJMainTable tr td

to specifically override that piece.

Alternatively, can you reduce the infobox selector to be less specific?

like image 69
Mike Cornell Avatar answered Oct 05 '22 22:10

Mike Cornell


You can actually specify which rule wins by using !important.

table.ATJMainTable tr td
{
    border: 1px solid black !important;
    padding: 3px !important;
}

This basically tells the browser, that it should make sure this rule is the most important rule and all others should be cascaded in favor of this rule.

warning: you will want to use this sparingly because it will cause issues if that are hard to track down if you use it too much.

like image 36
Nick Berardi Avatar answered Oct 05 '22 23:10

Nick Berardi


it's a more specific selector.

See here.

like image 21
Zack Marrapese Avatar answered Oct 06 '22 00:10

Zack Marrapese