CSS Child vs Descendant selectors

前端 未结 8 2156
心在旅途
心在旅途 2020-11-22 03:36

I am a bit confused between these 2 selectors.

Does the descendent selector:

div p

select all p withi

8条回答
  •  滥情空心
    2020-11-22 03:56

    In theory: Child => an immediate descendant of an ancestor (e.g. Joe and his father)

    Descendant => any element that is descended from a particular ancestor (e.g. Joe and his great-great-grand-father)

    In practice: try this HTML:

    Span 1. Span 2.
    Span 1. Span 2.

    with this CSS:

    span { color: red; } 
    div.one span { color: blue; } 
    div.two > span { color: green; }
    

    http://jsfiddle.net/X343c/1/

提交回复
热议问题