Is there a way to target a tags with img inside?
I need to target a
tags with img
inside them. Can I do this through css or do I have to use jQuery?
additional info from comment
I set a:hover { border-bottom:1px dotted #fff }
but I don't want the border to apply to a tag开发者_Python百科s with img
inside them.
There's no :has in css. In jQuery you can do
$("a:has(img)")
No, this cannot be done with CSS unless you're willing to mark the a
tags with a class or something similar.
Using jQuery, you can do something like this to match a
tags that have img
tags as direct children.
$('img').parent('a')
If you want to allow the img
to be any descendant, you can use the :has
selector.
$('a:has(img)')
May have misunderstood you, but do you mean this?
HTML: <a href="#"><img src="#"/></a>
CSS: #container a { border-bottom: 1px dotted #ccc; }
#container a img { border: 0 !important; }
This removes borders from images inheriting <a>
borders if set. Since you mentioned hover...
#container a img:hover { border: 0 !important; }
精彩评论