search

Home  >  Q&A  >  body text

css3 - CSS中first-child无效

我在CSS中输入#id:first-child{
xxx;
xxx;
}
这样用法有错吗?为什么我不用伪类,直接给需要的对象加了class,然后直接class引用才成功..

天蓬老师天蓬老师2864 days ago717

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 11:07:04

    MDN related introduction

    The first sub-element under id mentioned by the questioner is probably not used in this way.
    You are probably referring to the descendant selector. Can you determine the type of the child element? If so, just

    #id element:first-child{
    
    }
    

    For example, id is the first child element testul of li’s

    #test li:first-child{
        color:red;
    }
    

    Can you try this?

    #test *:first-child{
        color:red;
    }
    

    Effect:
    http://jsfiddle.net/8f2ff6ks/

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 11:07:04

    The first-child selector is used to select the specified selector that belongs to the first child element of its parent element

    reply
    0
  • Cancelreply