无法在CSS中选择Div中的第一个按钮

无法在CSS中选择Div中的第一个按钮,css,Css,请看一下此代码,并告诉我为什么无法选择div中的第一个按钮: .button-group-h button:first-child{ background-color:yellow; } <ul class="button-group-h"> <li><button class="btn button">Button</button></li> <li><button class="btn bu

请看一下此代码,并告诉我为什么无法选择div中的第一个按钮:

.button-group-h button:first-child{
  background-color:yellow;
} 

<ul class="button-group-h">
    <li><button class="btn button">Button</button></li>
    <li><button class="btn button">Button</button></li> 
    <li><button class="btn button">Button</button></li>
</ul>
.button-group-h按钮:第一个孩子{
背景颜色:黄色;
} 
  • 钮扣
  • 按钮
  • 钮扣

.button-group-h按钮:第一个子
选择器实际上选择并影响所有三个按钮。谢谢

使用
  • 上的
    :first child
    ,而不是按钮。
  • 元素是
      的子元素,而不是按钮:

      .button-group-h li:first-child button{
          background-color:yellow;
      } 
      

      使用
    • 上的
      :first child
      ,而不是按钮。
    • 元素是
        的子元素,而不是按钮:

        .button-group-h li:first-child button{
            background-color:yellow;
        } 
        

        使用
      • 上的
        :first child
        ,而不是按钮。
      • 元素是
          的子元素,而不是按钮:

          .button-group-h li:first-child button{
              background-color:yellow;
          } 
          

          使用
        • 上的
          :first child
          ,而不是按钮。
        • 元素是
            的子元素,而不是按钮:

            .button-group-h li:first-child button{
                background-color:yellow;
            }