简体   繁体   English

如何使用CSS选择图像

[英]how to select image using css

This is my html: 这是我的html:

<div id="content">
    <img src="myimg.png" alt="this image need to select"/>
    <div  class="some">
        <img src="another.png" alt="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 ie select all image directly inside the content div and not the ones that are inside the div or span of content div. 我想选择所有图像它们的ID内content ,但没有哪个是内divspancontent DIV即直接选择中的所有图像content的div和不属于内的那些divspan内容股利。

Any thoughts? 有什么想法吗?

You can use > to select direct/immediate children of the div like this: 您可以使用>选择div的直接/直接子级,如下所示:

#content > img{
  // target direct children
}

Check out the demo here (the desired image is given blue border) 在此处查看演示 (所需的图像带有蓝色边框)

More Info: 更多信息:

不是专家,但这应该可行-> div#content > img

you can write 你可以写

#content > img {

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM