Reputation: 5494
I have the following HTML and CSS code:
HTML:
<a href="http://www.google.com/" target="_blank"><img src="image.jpg" /></a>
CSS:
a:hover {
border-bottom:1px solid #000;
}
The issue is, that the a-Tag should add the border when hovering only if the enclosed link is NOT an image.
The border is not on the image, it is on the a-Tag...How can I solve this?
Is there a solution for this?
Upvotes: 0
Views: 344
Reputation: 81
use following CSS for anchor image link:
a img { border: none; }
a:hover img { border: none; }
Upvotes: 0
Reputation: 106058
CSS cannot do this , but Jquery can easily help you :
$(document).ready(function(){
$("img").parent("a").css( "border-bottom" , "none" );
});
test it here : http://codepen.io/anon/pen/zGZbVj
Upvotes: 1
Reputation: 3933
a img, a img:hover { border:none; }
if you have only one a-tag that has an image, you can use an id
#myImageATag, #myImageATag:hover{
border:none;
}
<a id="myImageATag"></a>
If you wan to apply to many others, you can use a class
.linksWithImages, .linksWithImages:hover{
border:none;
}
I don't know if you can use Jquery but this is a solution to check if there is an image then remove the border. How to check if the a tag has an image below in jQuery
$('a').each(function() {
if ($(this).find('img').length === 0) {
$(this).css("border", "none");
}
});
Upvotes: 1