html - 覆盖除 img 之外的所有内容

标签 html css css-transitions

我正在尝试在图像上添加叠加层。一切正常,除了叠加层不会覆盖容器的图像部分。我增加了 z-index 并将 bottomleftright 等添加到 0。

有没有人看到我做错了什么?我很难过。

.pdfWrap {
  border-top: 1px solid #CFCFCF;
  border-right: 1px solid #CFCFCF;
  border-bottom: 1px solid #CFCFCF;
  border-radius: 2px;
  position: relative;
  height: 260px;
  width: 25%;
  display: inline-block;
  vertical-align: top;
  text-align: center;
  cursor: pointer;
  transition: all .35s ease;
  -webkit-transition: all .35s ease;
  transition-delay: 0.10s;
  -webkit-transition-delay: 0.10s;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.pdfWrap .overlay {
  z-index: 11111;
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
  right: 0;
  position: absolute;
  cursor: pointer;
  transition: all .35s ease;
  -webkit-transition: all .35s ease;
}

.pdfWrap:hover .overlay {
  background-color: rgba(0, 0, 0, 0.6);
  transition: all .35s ease;
  -webkit-transition: all .35s ease;
  transition-delay: 0.10s;
  -webkit-transition-delay: 0.10s;
  z-index: 10;
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
  right: 0;
  position: absolute;
  cursor: pointer;
  display: block;
}

.pdfBox img {
  width: 60%;
  height: auto;
  margin: 0 auto;
  background: transparent;
}
<div class="pdfWrap">
  <div class="overlay">
    <div class=" pdfBox total-center">
      <img src="https://mbkitsystems.com/images/linear-motion/linear_structure.jpg" alt="">
      <h3 class="pdfTitle">Linear Structure</h3>
    </div>
  </div>
</div>

最佳答案

您需要为独立于内容部分的叠加层制作一个单独的 div...

.pdfWrap {
  border-top: 1px solid #CFCFCF;
  border-right: 1px solid #CFCFCF;
  border-bottom: 1px solid #CFCFCF;
  border-radius: 2px;
  position: relative;
  height: 260px;
  width: 25%;
  display: inline-block;
  vertical-align: top;
  text-align: center;
  cursor: pointer;
  transition: all .35s ease;
  -webkit-transition: all .35s ease;
  transition-delay: 0.10s;
  -webkit-transition-delay: 0.10s;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.pdfWrap .overlay {
  z-index: 11111;
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
  right: 0;
  position: absolute;
  cursor: pointer;
  transition: all .35s ease;
  -webkit-transition: all .35s ease;
}

.pdfWrap:hover .overlay {
  background-color: rgba(0, 0, 0, 0.6);
  transition: all .35s ease;
  -webkit-transition: all .35s ease;
  transition-delay: 0.10s;
  -webkit-transition-delay: 0.10s;
  z-index: 10;
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
  right: 0;
  position: absolute;
  cursor: pointer;
  display: block;
}

.pdfBox img {
  width: 60%;
  height: auto;
  margin: 0 auto;
  background: transparent;
}
<div class="pdfWrap">
  <div class="overlay"></div>
  <div class=" pdfBox total-center">
    <img src="https://mbkitsystems.com/images/linear-motion/linear_structure.jpg" alt="">
    <h3 class="pdfTitle">Linear Structure</h3>
  </div>
</div>

关于html - 覆盖除 img 之外的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49369740/

相关文章:

html - 无法将图像居中

css - 多个 CSS 过渡

javascript - 如何手动触发 Ratchet 的推送?

html - 如何让预加载器隐藏滚动条?

html - 更改样式输出以使其不带下划线

javascript - 更改所有页面的 CSS

CSS延迟过渡

html - 为一条线设置动画并使其成为 au turn css3

python - 如何在 Pootle 中按总体完成情况显示排序列表

html - 在 div 之间应用空间