1
2
3
4
5
6
7
8
| < div id = "container" > < p >First</ p > < div > < p >Child Paragraph</ p > </ div > < p >Second</ p > < p >Third</ p > </ div > |
Space:
1
2
3
| div#container p{ font-weight : bold ; } |
> Sign:
It will target elements which are DIRECT children of a particular element.
1
2
3
| div#container > p { border : 1px solid black ; } |
It will target all P element which are direct children of container div, not children of child div.
+ Sign:
It is Adjacent sibling combinator. It combines two sequences of simple selectors having the same parent and the second one must come IMMEDIATELY after the first.
1
2
3
| div + p { color : green ; } |
It will only select the first element that is immediately preceded by the former selector. In our example, it will target to Second ONLY because the owner P element comes just after Div tag.
~ Sign:
It is general sibling combinator and similar to Adjacent sibling combinator. the difference is that the second selector does NOT have to immediately follow the first one means It will select all elements that is preceded by the former selector.
1
2
3
| div ~ p{ background-color : blue ; } |
It will target both second and third.
Hope, you enjoyed this.
(http://techbrij.com/654/css-selector-adjacent-child-sibling)
Không có nhận xét nào:
Đăng nhận xét