Reputation: 3721
I have the following scenario.
I need to customize all links on a website to have an orange background.
.have-all-links-orange a{
background-color: #F59522;
}
however when I do this all images inside an A get the same background, I tried with this but didn't do the trick
.have-all-links-orange a img{
background-color: transparent;
}
Any ideas on how may I fix this?
Upvotes: 0
Views: 252
Reputation: 4137
If you have to have your images in a different display, you can always use jquery to get rid of the color:
https://jsfiddle.net/616d530s/2/
$('.have-all-links-orange a img').closest('a').css('background', 'transparent');
Upvotes: -1
Reputation: 60573
because img
is by default an inline element therefore creates a gap and has vertical-align:baseline
by default.
display:block
in img
.have-all-links-orange a {
background-color: #F59522;
}
.have-all-links-orange a img {
background-color: transparent;
display: block
}
<div class="have-all-links-orange">
<a href="www.google.com">
<img src="https://www.google.com.pe/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png">
<br />
<a href="http://www.google.com">click here<a>
<div>
Upvotes: 2
Reputation: 4358
You can do this
.have-all-links-orange a img {
background-color: transparent;
display: block;
}
How to get anchor tag on background image of div?
Upvotes: 1
Reputation: 1645
make the image a block element.
.have-all-links-orange a img {
display: block;
background-color: transparent;/**You don't need this**/
}
Upvotes: 1
Reputation: 5561
Hm.. maybe like this? You did say "ALL of the links to have oragne background".
a {
background-color: #F59522;
}
Upvotes: -1