简体   繁体   中英

Or and > with CSS selectors

Is it possible to use a comma in the CSS selector if you are also using > selector?

I want to do something like this, but this syntax didn't work:

#id ul > li.class1, li.class2 > a {
    color: red !important;
}

Is this possible?

Thanks!!

The , operator only works between complete selectors, not between parts of a selector. You have to repeat all of the selector:

#id ul > li.class1 > a, #id ul > li.class2 > a {
  color: red !important;
}

You can use them.

, is used to seperate different CSS selections. Whereas > is a Child selector and all that kind of things.

Use of comma would seperate each selection and you won't get to the heirarchy if you meant to select a inside each of the element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM