Fred Wilson Fred Wilson - 1 month ago 5
CSS Question

CSS Refactoring with tag id

I do not have a firm grasp on CSS Selectors.
I know the below CSS is sparse but it will get me going.

I want a table's borders to be the same for th and td.

#eventRegistrationNotificationEmail th{
width:25%;
border: 1px solid #999999;
}

#eventRegistrationNotificationEmail td{
width:75%;
border: 1px solid #999999;
}


I know I can do something like the below but how do I do it with an ID or Class?

td, th{
border: 1px solid #999999;
}

Answer

You can do it exactly the same way, just separate your selectors with a comma and the style is applied to all of them.

#eventRegistrationNotificationEmail td, 
#eventRegistrationNotificationEmail th {
    border: 1px  solid #999999;
}

You could also use a CSS pre-processor like LESS which lets you next styles in the .less file which are combined together when the processor is run:

#eventRegistrationNotificationEmail {
    td, th {
        border: 1px solid #999999;
    }
}
Comments