How to target a specific

前端 未结 6 769
北恋
北恋 2021-02-08 20:27

I\'ve a code of some what like this:

6条回答
  •  梦如初夏
    2021-02-08 21:12

    All of the following solutions only work in recent browsers.

    You can select by child position:

     #foo img:first-child { /* for the bar */ }
     #foo img:nth-child(2) { /* for the cat */ }
    

    You can select by child position, counting only images:

     #foo img:first-of-type { /* for the bar */ }
     #foo img:nth-of-type(2) { /* for the cat */ }
    

    You can select by image URL:

     #foo img[src^=bar] { /* for the bar */ }
     #foo img[src^=cat] { /* for the cat */ }
    

提交回复
热议问题