Search code examples
cssstylesheetcss-selectorssiblings

css: many sibling selectors on the same line


In my stilesheet I have something similar of what follows:

h2.foo1 ~ p.bar1 {
...
} 
h2.foo2 ~ p.bar2 {
...
} 
h2.foo3 ~ p.bar3 {
...
} 

Since the properties defined within brackets are the same for all, can I combine the above lines in only one, and how? That is, something similar to:

h2.foo1 ~ p.bar1 (?) h2.foo2 ~ p.bar2 (?) h2.foo3 ~ p.bar3(?) {
... 
}

Solution

  • Comma.

    h2.foo1 ~ p.bar1, h2.foo2 ~ p.bar2, h2.foo3 ~ p.bar3 {
    ...
    }