css - 同一个 DIV 中具有不透明背景的图像和文本

标签 css html background opacity

我正在尝试制作不透明的图像和文本!

背景出现在同一个 div 中,而不使用图像作为背景。我怎样才能使这项工作?

请看图片:

最佳答案

<div>
  <span>Title</span>
  <img src="" />
</div>

div{
  position: relative;
}
span{
  background: rgba(0,0,0,0.5);
  position: absolute;
  bottom: 0;
  left: 0;
  padding: 6px;
  display: block;
}

关于css - 同一个 DIV 中具有不透明背景的图像和文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11260324/

相关文章:

html - 将 CSS 规则应用于与多个可能属性值之一匹配的元素

javascript - Bootstrap JS 在本地机器上不起作用

html - 为非滚动创建固定位置会弄乱页面上的 div 位置

jquery - 背景图像上方的背景颜色

css - 使用 CSS wave 的动画文本

html - css 将输入中的文本垂直对齐到顶部

html - 为什么文本在列表元素中的位置不正确?

javascript - 动态垂直对齐文本

css - Div 背景宽度浏览器

android - 修订版 2 : How to pass data from a background Service/thread to some other activity than the MainActivity that created the background service