html - 在透明图像上显示内容
问题描述
我正在尝试在图像上显示 html 元素(表单、文本等),该图像已通过 gimp 变得透明。但是无论我尝试了什么,内容都被图像隐藏了。
我已经更改了页面的背景颜色,只是为了确保浏览器没有出于某种原因将透明部分更改为白色,但事实并非如此。
我也尝试过使用 z-index 属性,但这没有用。
重新加载页面时,我可以看到文本正确显示,但随后图像显示并覆盖它。
#foo{
position: relative;
}
#foo img{
width: 20%;
height: 20%;
}
#bar{
position: absolute;
}
<!DOCTYPE html>
<body>
<div id='foo'>
<img src='my_img' />
<div id='bar'>
<!--This is where I want to write what will be displayed on the transparent image.-->
</div>
</div>
</body>
我没有发现任何类似的情况,也没有在其他网站上找到,所以欢迎任何建议。
编辑:实际上我设置了顶部和左侧的 CSS 属性,现在它工作正常。
解决方案
您是否考虑过背景图像?
#bar {
background-image: url('/path/to/myimg.jpg');
background-size: contain;
background-position: center center;
}
推荐阅读
- java - 我的 Max Counters codility 挑战的解决方案有什么问题
- php - file_get_contents() 需要时间通过外部服务器加载内容 - PHP
- github - 添加新文件时是否会影响 Gradle 文件
- pip - pip 如何知道要抓取哪个 Wheel 以与您的系统一起使用?
- python - 如何将列表切割成第二个列表,其中包含以相同字母开头的项目
- python - 基于第一个月的python pandas中的每周数据操作
- sql - 从一列计算相同的出现次数并将增量计数存储在新列中
- node.js - asyncLocalStorage 在错误中间件中丢失上下文?
- node.js - IIS 上的 Windows 身份验证和标头中包含用户/角色的节点代理?
- python - Python正则表达式findall()没有返回所需的列表