首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么overlay没有响应?

为什么overlay没有响应?
EN

Stack Overflow用户
提问于 2018-08-16 19:10:56
回答 2查看 51关注 0票数 0

所以我有一个容器/div,里面有六张照片。在每一张照片中,当我悬停在它上面时,我想要有一个覆盖。但覆盖覆盖了整个div,而不仅仅是照片尺寸。也许问题是我有课?每个单独的照片都有六个css,这不是很糟糕吗?

下面是html:

代码语言:javascript
复制
<div id="info-pics">
    <div id="info-pics-container">
        <div class="info-pic-top">
        <img src="service-1.jpg" alt="service-1" style="width:100%;height:100%;">
            <div class="overlay">
                <div class="overlay-text">Ύστερα από συνεννόηση με εσάς αναζητούμε τις πιο προσιτές και κατάλληλες δυνατότητες και
ταιριαστά σχέδια ώστε να πετύχουμε ένα όμορφο αποτέλεσμα.
                </div>
            </div>
        </div>
        <div class="info-pic-top">
        <img src="service-2.jpg" alt="service-2" style="width:100%;height:100%;">
            <div class="overlay">
                <div class="overlay-text">Hello World
                </div>
            </div>
        </div>
        <div class="info-pic-top">
        <img src="service-3.jpg" alt="service-3" style="width:100%;height:100%;">
            <div class="overlay">
                <div class="overlay-text">Hello World
                </div>
            </div>
        </div>
        <div class="info-pic-top">
        <img src="service-4.jpg" alt="service-4" style="width:100%;height:100%;">
            <div class="overlay">
                <div class="overlay-text">Hello World
                </div>
            </div>
        </div>
        <div class="info-pic-top">
        <img src="service-5.jpg" alt="service-5" style="width:100%;height:100%;">
            <div class="overlay">
                <div class="overlay-text">Hello World
                </div>
            </div>
        </div>
        <div class="info-pic-top">
        <img src="service-6.jpg" alt="service-6" style="width:100%;height:100%;">
            <div class="overlay">
                <div class="overlay-text">Hello World
                </div>
            </div>
        </div>
    </div>
</div>

下面是CSS:

代码语言:javascript
复制
#info-pics {
    position:relative;
    height:800px;
}
#info-pics-container {
    background-color:grey;
    position:absolute;
    width:75vw;
    height:30vw;
    left:13%;
    top:15%;
}
/* Container needed to position the overlay. Adjust the width as needed */
.info-pic-top {
  float: left;
  width: 33.33%;
  height:50%;
  padding: 5px;
}
/* The overlay effect (full height and width) - lays on top of the container and over the image */
.overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: #008CBA;
  overflow: hidden;
  width: 100%;
  height: 100%;
  transform: scale(0);
  transition: .3s ease;
}
/* When you mouse over the container, the overlay text will "zoom" in display */
.info-pic-top:hover .overlay {
  transform: scale(1);
}
/* Some text inside the overlay, which is positioned in the middle vertically and horizontally */
.overlay-text {
  color: white;
  font-size: 20px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-08-16 19:14:30

代码语言:javascript
复制
Just add position:relative

    .info-pic-top {
      float: left;
      width: 33.33%;
      height:50%;
      padding: 5px;
      position:relative;
    }
票数 3
EN

Stack Overflow用户

发布于 2018-08-16 19:13:49

您错过了向选择器info-pic-top添加position: relative。试试这段代码。

代码语言:javascript
复制
.info-pic-top {
  float: left;
  width: 33.33%;
  height:50%;
  padding: 5px;
  position: relative;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51875645

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档