How to select multiple elements that are children of given element?

后端 未结 3 1030
北恋
北恋 2020-12-24 05:10

I have

and I need to select all pre and div elements that are children of #mydiv.

I coul

3条回答
  •  被撕碎了的回忆
    2020-12-24 05:54

    The only way to reference the id only once is to use it with the * selector:

    #mydiv > * {
    

    which will apply to all elements that are children of that div.

    Depending on what styles you plan to apply this might be workable (I typically use this to zero-out margins, padding and border styles), but it's still probably best to do it the first way because it makes it easier to make exceptions/changes later down the road.

提交回复
热议问题