Is there a way to group CSS selectors for clarity?

If I have a dozen CSS selectors and want to assign :hover properties to all of them, I'm used to it:

 selector, selector2, someOtherSelector, someSelector div { //some properties } selector:hover, selector2:hover, someOtherSelector:hover, someSelector div:hover { //some properties } 

Input :hover four times seems redundant. Is there a way to group type selectors

 (selector, selector2, someOtherSelector, someSelector div):hover { //some properties } 

instead

+7
source share
3 answers

If they all have the same guidance properties, you can create a class common to all that your defines: hover

So you get:

 allSelectors, selector, selector2, someOtherSelector, someSelector div { //some properties } allSelectors:hover { //some properties } 

Repeatable classes do for cleaner and smaller code.

+4
source

Not natively in CSS. Using SCSS , you can write:

 selector, selector2, someOtherSelector, someSelector div { // some properties &:hover { // some more properties } } 
+4
source

Unfortunately, not an entirely easier way to do what you are trying to do, unfortunately. If you do not want to move styles in jQuery or something (but this is not a good solution).

+3
source

All Articles