Apply CSS rules to a nested class inside a div

前端 未结 3 1384
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-30 16:27

I don’t know exactly how to apply CSS to a nested element. Here is my example code, but I’m looking for a manual that explains all the rules:

3条回答
  •  星月不相逢
    2021-01-30 16:44

    You use

    #main_text .title {
      /* Properties */
    }
    

    If you just put a space between the selectors, styles will apply to all children (and children of children) of the first. So in this case, any child element of #main_text with the class name title. If you use > instead of a space, it will only select the direct child of the element, and not children of children, e.g.:

    #main_text > .title {
      /* Properties */
    }
    

    Either will work in this case, but the first is more typically used.

提交回复
热议问题