开发者

how to select image using css

This is my html:

<div id="content">
    <img src="myimg.png" alt="this image need to select"/>
    <div  class="some">
        <img src="another.png" alt="开发者_StackOverflow社区this is not need  to select"/>
    </div>   
</div>

I want to select all image which are inside id content but not which are inside the div or span of content div i.e. select all image directly inside the content div and not the ones that are inside the div or span of content div.

Any thoughts?


You can use > to select direct/immediate children of the div like this:

#content > img{
  // target direct children
}

Check out the demo here (the desired image is given blue border)

More Info:

  • http://www.456bereastreet.com/archive/200510/css_21_selectors_part_2/


Not an expert, but this should work -> div#content > img


you can write

#content > img {

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜