html - 如何在css和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 或其他透明图像才能通过图像查看背景。
推荐阅读
- python - 将脚本作为并行子进程运行
- apache-kafka - 卡夫卡期待地关闭。无法创建许可证主题
- visual-studio - 无法在 Visual Studio 2019 中下载 Android 模拟器
- swift - 如何减少 SwiftUI 中大量图像的内存占用
- node.js - Node.Js HTTP 响应中断
- mysql - 每周统计看到的用户
- ios - 如何在 Xcode 12 中使用 iOS 12 模拟器
- sql-server - 从更改跟踪表中读取 - 什么事务隔离级别?
- javascript - 打字稿:检查特定函数是否返回值?
- oracle - 使用动态变量插入表 PLSQL