user10031694
user10031694

Reputation: 221

How to add background color to image property in css and html

I am trying to change the background color of my image. Normally, to do this, I use;

.img {
background-image: url("./image.jpg");
background-color: "#3333";
}

But I am trying to do the same thing using the html img tag. But this doesn't seem to work. So in a form;

<div class="container">
  <img class="image" src="./image.jpg"/>
</div>

Upvotes: 0

Views: 277

Answers (1)

MartinM43
MartinM43

Reputation: 101

In css...

.name -> Style is assigned to a "class="
#name -> Style is assigned to an "id="
 name -> Style is assigned to an tag <name></name>

You can try this: (Change .img to img in your CSS)

img {
 background-image: url("./image.jpg");
 background-color: #333;
}

<div class="container">
  <img class="image" src="./image.jpg"/>
</div>

Note: You will probably need a .png or other transparent image to see the background through the image.

Upvotes: 1

Related Questions