How to target a specific

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

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

6条回答
  •  野的像风
    2021-02-08 21:05

    I don't know why everyone is so fixed on the #foo div. You can target the img tag and not even worry about the div tag. These attribute selectors select by the "begins with".

    img[src^=bar] { css }
    img[src^=cat] { css }
    

    These select by "contains".

    img[src*="bar"] { css }
    img[src*="cat"] { css }
    

    Or you can select by the exact src.

    img[src="bar.png"] { css }
    img[src="cat.png"] { css }
    

    If you want to target them both, then you could use the div id.

    #foo img { css }
    

    For just one of the images, there is no need to worry about the #foo div at all.

提交回复
热议问题