如何使用CSS选择图像

0 html javascript css

这是我的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>
Run Code Online (Sandbox Code Playgroud)

我想选择所有图像它们内部ID content而不是它是内部的divspancontentDIV即直接选择中的所有图像contentDIV,而不是其内部的的那些divspan内容股利.

有什么想法吗?

Sar*_*raz 8

您可以使用>这样选择div的直接/直接子项:

#content > img{
  // target direct children
}
Run Code Online (Sandbox Code Playgroud)

在这里查看演示(所需图像为蓝色边框)

更多信息: