I have <div id='mydiv'> and I need to select all pre and div elements that are children of #mydiv.
I could do it this way:
div#mydiv > pre, div#mydiv > div but, can it be done so that #mydiv is referenced only once?
div#mydiv > pre, div will select all divs on the page regardless if they're children of #mydiv, so the comma isn't a way to do it. Maybe there's another kind of syntax I don't know about?
To create a CSS child selector, you use two selectors. The child combinator selects elements that match the second selector and are the direct children of the first selector. Operators make it easier to find elements that you want to style with CSS properties.
The child combinator ( > ) is placed between two CSS selectors. It matches only those elements matched by the second selector that are the direct children of elements matched by the first. Elements matched by the second selector must be the immediate children of the elements matched by the first selector.
While pressing Ctrl, click each of the elements. NoteIf you are selecting multiple elements and need to use the Tab key to select an element in close proximity to others, do not hold the Ctrl key while pressing Tab.
You'll have to reference #mydiv twice...
#mydiv > pre, #mydiv > div I removed the extraneous div element selector as the ID is specific enough.
As far as I know, there is no shorthand for selector grouping.
See "Selector Grouping".
Although, with LESS, it is possible in the "Nested Rules" section.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With