簡體   English   中英

如何在 css 和 html 中為圖像屬性添加背景顏色

[英]How to add background color to image property in css and html

我正在嘗試更改圖像的背景顏色。 通常,為此,我使用;

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

但我正在嘗試使用 html img 標簽做同樣的事情。 但這似乎不起作用。 所以以一種形式;

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

在 css...

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

你可以試試這個:(在你的CSS中將.img更改為img)

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

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

注意:您可能需要一個 .png 或其他透明圖像才能通過圖像查看背景。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM