叠加覆盖除img之外的所有内容

时间:2018-03-19 18:11:51

标签: html css css3 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>

1 个答案:

答案 0 :(得分:4)

您需要为叠加层单独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>