The markup below aligns SAMPLE TEXT to the left.
To me, it seems like it should be aligned to the right. The class that aligns to the right is declared after the one that aligns left. And the class that aligns to the right is even referenced last. So why does the class that aligns to the left win?
CSS
.table {
width: 100%;
}
.table td {
text-align: left;
}
.cell {
text-align: right;
}
HTML
<table class="table">
<tr>
<td class="cell">
SAMPLE TEXT
</td>
</tr>
</table>
Please see my jsFiddle Example.
The
.table tdselector has a higher specificity. CSS specificity rules are kind of weird… IDs weigh more than class names, which weigh more than tag names.The specificity rules, in a nutshell:
The higher values will always override the lower ones. In the case of a tie, the last rule loaded wins.