我有一些无法更改的代码,如下所示:
<div id="wombat">
<a href=""><img src="a"></a>
<img src="b">
</div>
我只想定位 img b。 #wombat img {blah} 得到了他们两个。我知道 #wombat a img 只会针对 img a,但有没有办法只针对 img b?
谢谢!
最佳答案
您可以使用兄弟或后代运算符,具体取决于您要实现的目标:
#wombat > img {
/* any images that reside directly below #wombat, without any more levels in between */
}
a ~ img {
/* any image that follows as a sibling to an anchor */
}
a + img {
/* an image that follows as direct sibling to an anchor */
}
参见:
关于html - 当两者都在同一 ID 内时,如何仅选择不在链接内的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19591555/