Different types of Combinators in CSS.
1499
13-Oct-2016
Abhishek Srivasatava
13-Oct-2016Combinators in CSS (Cascading Style Sheet)
Descendant selector (space)
It is used when we need to apply all property to all the declare member.
For example
Then the entire h1 tag inside the div will have background color as red.
Child selector (>)
It is used for the entire element which is child element of the main element.
For example:
In the above example 1st h1 and 2nd h1 will have blue color, whereas there will be no impact on tag p, and 3rd h1.
Adjacent sibling selector (+)
It is used for the element which is just after the defined elements or we can say adjacent element.
For example:
In the above example, there will be no impact on 1st h1, 2nd h1, 4th <h1> and tag <p>.
Only 3rd h1 will have background color as blue
General sibling selector (~) not
We can say it is similar to Not condition because property will not impact on declare element. But for rest it will impact.
In the above example there will be no impact on 1st <h1>, 2nd <h2>, 1st <p>, and 2nd <p>.
But 3rd<h1> and 4th h1 will have background color as blue.