When using CSS, I can query elements in the following ways:
div > .class
div .class
div + .class
However I can't quite tell the exact difference between each of these DOM
queries. Do they all point to child elements? I know that ">" and " " (space) do.
But under what circumstances would I use each?
Answer
In CSS these are called Combinators and means three different things:
div > .class
: is called Child selector and will select all elements that are direct children of adiv
and have the class.class
.div .class
: is called Descendant selectors and will select all elements inside a div and having the class.class
.div + .class
: is called Adjacent sibling selector and will match any element that immediately follows adiv
and have the class.class
.
Example:
In the following example:
A title
No comments:
Post a Comment