嵌套在css部分中的div元素的样式

问题描述 投票:-1回答:3

如何设置嵌套在节中的div元素的样式,这是我尝试过的方法,但是却收到期望“}”的错误;

#section1
{

    color: blue;

    #div1 {
        color: red;
      }

}
html css
3个回答
0
投票

如果有ID,则可以直接选择ID:

#div1 {
    // your style here
}

或您可以将CSS选择器与其ID结合使用:

div#section1 div#div1 {
    // your style here
}

0
投票

如果您仅使用CSS,请尝试一下,

#section1
 {
color: blue;  
 }

  #section1 #div1 
    {
  color: red;
  }

0
投票

如果不使用较少或简单的方法,则不应编写嵌套类。唯一可以使用的就是将您的班级分为2个班级:但是您也只能使用#div 1代替#section1#div1。

#section1 {
    color: blue;
}

#section1 #div1 {
    color: red;
}
<div id="section1">
   ABC
   <div id="div1">
     XYZ
   </div>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.