html - CSS 文本覆盖图像

标签 html css

我想像这样在图像上放置文字:

.gallery-image {
  position: relative;
}
h2 {
  position: absolute;
  top: 200px;
  left: 0;
  width: 100%;
}
h2 span {
  color: white;
  font: bold 24px/45px Helvetica, Sans-Serif;
  letter-spacing: -1px;
  background: rgb(0, 0, 0);
  background: rgba(0, 0, 0, 0.7);
  padding: 10px;
}
<div class="gallery-image">
  <a href="#">
    <img src="image.jpg" width="280">
  </a>
  <h2><span>Text</span></h2>
</div>

但是我的文字在图片后面,我该怎么做才能解决这个问题?

最佳答案

无论如何,Snippet 对我有用:

  • img一个z-index: 2;

  • h2一个z-index: 3;

关于html - CSS 文本覆盖图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27864800/

相关文章:

javascript - 我怎样才能改变我的计时器数字的跨度冒号的颜色?

javascript - jquery Microsoft Word/Google Docs 分页

javascript - 每行内都有一个嵌套表的数据表

javascript - 设置 Canvas 大小时不显示图像

JavaScript 数据表 : remove unwanted horizontal scrolling

html - 在整体包装之前,我怎样才能在内部有一个内部 div 包装?

html - Angular:选择下拉列表中的最大选择

javascript - 如何使用 CSS 隐藏元素溢出?

css - 在没有自定义 css 文件的情况下对齐 Bootstrap 列表组中的徽章项

jquery - 无间隙的 masonry 画廊布局