0

I am working with CSS selector symbols to create complex element selectors. I am currently stuck with selector symbols which I cannot create combinations with.

For instance, I am trying to create: body and children elements of body that are not of #foo id using

body > *:not(#main-div) + body

but the combinations of the elements don't work. I have used each of the selectors individually at least once before, but never tried their combinations. This feature seemed very useful to me and so I wanted to know whether it is possible to create combinations of these selector symbols. If yes, what is the correct syntax to follow?

2
  • + should be , Commented Jun 4, 2020 at 19:26
  • body, body > *:not(#main-div) Commented Jun 4, 2020 at 19:27

2 Answers 2

2

In order to apply styles to both the body and all immediate children of the body (excluding the #main-div) element, you should use the following selector list:

body,
body > *:not(#main-div) {
  ...
}

Commas should be used to group selectors into selector lists. The + is an adjacent sibling combinator.

The Mozilla Developer Docs has a great primer on forming CSS selectors and rulesets here: https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the documentation. It was genuinely what I was looking for.
0

This feature seemed very useful to me and so I wanted to know whether it is possible to create combinations of these selector symbols. If yes, what is the correct syntax to follow?

Yes it is possible but i think the syntax you are using is incorrect instead you must use

body > :not(#main-div),body

And according to me there's no use of * and + because by even not mentioning * it will exclude all the id's that are #main-div and + is only used when the element is right after the current element.

6 Comments

This applies the selector to only children of body and not body also. Also, the question is not answered sufficiently. If you could elaborate your answer as to how to use these features, it would be more insightful. Your answer solves an example, not the question asked. I hope this comment helps you improve your answer.
Yes sure i'll do it.
Check out my edited answer now it will consider body itself too in the css
I'm sorry as i can't enter the other comment section i just want to tell you that yes it is true that css is excuted from left to right .
No actually here it remains only till comma , where specified ,it cannot and will never inherit the properties seperated by commas.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.