How can I use the same CSS attribute for multiple selectors?

Please tell me a simpler / shorter way to write this CSS:

.ads h3{
color: #f7f7f7;
}
.ads p{
color: #f7f7f7;
}
.ads blockquote{
color: #f7f7f7;
}

This is the right pain at the moment and takes place in the CSS file ...

+3
source share
7 answers

God says yes

"Your prayers were answered by my child."

.ads h3, .ads p, .ads blockquote {
    color: #F7F7F7;
}

And even taking it further (if there are no children, which also should not be colored):

.ads * {
    color: #F7F7F7;
}

And if you are fine with the text inside the paragraph itself, to have the same gray color:

.ads {
    color: #f7f7f7;
}

This will be overridden by any other styles that were set to p, blockquote, or h3, so you might want to take it further:

.ads, .ads * {
    color: #f7f7f7;
}
+6
source

, , . , :

.ads h3, .ads p, .ads blockquote {
   color: #f7f7f7;
}

. CSS 2.1, 5.2.1.

+7

If there are no other redefinition rules that you did not specify, this will be fine:

.ads 
{
color: #f7f7f7;
}
+1
source

You can write it down to make it simpler / shorter.

.ads h3, p, blockquotes{
color: #f7f7f7;
}
+1
source
.ads h3, .ads p, .ads blockquote{
  color: #f7f7f7;
}
0
source
.ads h3,
.ads p,
.ads blockquote {
  color: #f7f7f7;
}
0
source

You don't need the final one ;(per YUI CSS Min )

.ads h3,.ads p,.ads blockquote{color:#f7f7f7}
0
source

Source: https://habr.com/ru/post/1793948/


All Articles