Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to apply background color on <img> tag?

Tags:

html

jquery

css

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

like image 286
vjy tiwari Avatar asked Sep 06 '17 06:09

vjy tiwari


People also ask

Can we set background image for IMG tag?

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.

Can we apply background color for an image in CSS?

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.


1 Answers

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;">
like image 106
Maulik Avatar answered Sep 25 '22 01:09

Maulik