Is there a way to apply background color on <img>
tag ?
<img src="abc.jpg" style="background-color:red;">
Above code is not working .
Please help me .
Thanks
The most common & simple way to add background image is using the background image attribute inside the <body> tag. The background attribute which we specified in the <body> tag is not supported in HTML5. Using CSS properties, we can also add background image in a webpage.
The background-color property in CSS is used to set the background color of an element. It applies solid colors as the element's background. The background of an element covers the total size, including the padding and border, but excluding margin. It can be applied to all HTML elements.
Yes it's possible. You just need to apply padding to image. Then you can get the result below:
or
You also can use .png images and apply transparent property.
img {
max-width: 50%;
}
<img src="http://pngimg.com/uploads/mario/mario_PNG53.png" style="background-color:red;padding:20px;">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With