CSS selector for class descendant within a class

前端 未结 3 1170
予麋鹿
予麋鹿 2020-12-12 01:23

Is it possible to create a CSS selector for \'element with class b, which is a descendant of an element with class a\'?

Thanks, Rasto

3条回答
  •  一向
    一向 (楼主)
    2020-12-12 02:11

    Given the mark-up:

    first B element
    first C element
    Second B element

    Yeah, for all descendants:

    .elementClassA .elementClassB {
    }
    

    The above will target both the first B element and the Second B element: JS Fiddle demo.

    For immediate descendants:

    .elementClassA > .elementClassB {
    }
    

    This will target only the first B element: JS Fiddle demo.

    References:

    • `CSS Selectors.

提交回复
热议问题