Nets Nets - 4 months ago 15
CSS Question

How to have different table styles in CSS

I have different tables in my page which should have different border, cellpadding etc. I can create many classes like,

.pad5 td {padding:5px}


and then using,

<table class="pad5">


But if I use 'table' is css, the style is applied to all tables. How can I achieve the result?

Answer

declare classes for each type of styling you want to create, and assign to the <table> in the html via the class attribute

css

.table1 {
    ...
}

.table2 {
    ...
}

html

<table class="table1">
    ...
</table>

<table class="table2">
    ...
</table>