How to apply CSS to only immediate children of a certain class

后端 未结 3 423
余生分开走
余生分开走 2020-12-11 00:24

I have a div and in that div I want to create another div with a different class and have the inner div completely separa

相关标签:
3条回答
  • 2020-12-11 00:45
    .outer > h2 { color:red; }
    

    this way only the direct child of the outer div get this color value, should fix the job.

    0 讨论(0)
  • 2020-12-11 00:47

    I think what you need is

    .inner h2 {color: inherit}
    
    0 讨论(0)
  • 2020-12-11 00:50
    .outer .inner * { color: #000; }
    

    sets all elements within the inner container as having the color black.

    Demo here

    0 讨论(0)
提交回复
热议问题