html - SCSS overlay display none 还在显示

标签 html css sass overlay

在使用 SASS 的同时在投资组合网站上工作-

我希望我的元素标题在鼠标悬停时显示在图像底部。

我还没有尝试过悬停,但如果可能的话,我将不胜感激!

HTML:

<div class="projects">
      <div class="item">
      <img src="img/projects/project1.jpg" alt="Project">
      <div class="overlay">TRACKFIT</div>
      <a href="#!" class="btn-dark">
        <i class="fab fa-behance"></i>
      </a>
      </div>

CSS:

.projects {
  display: grid;
  grid-gap: 0.7rem;
  grid-template-columns: repeat(3, 1fr);

  img {
    width: 100%;
    border: 3px #fff solid;

    &.overlay {
      display: none;
    }

    &:hover {
      opactiy: 0.5;
      border-color: $secondary-color;
      @include easeOut;
    }
  }
}

The "TRACKFIT" text it still displaying beneath the image, regardless of the overlay display:none

非常感谢!

最佳答案

https://jsfiddle.net/kendra_chu/19qte5rh/4/

.projects{
  display: grid;
  grid-gap: 0.7rem;
  grid-template-columns: repeat(3, 1fr);
  .item{
     img{
          width: 100px;
          border: 3px #fff solid;   
          position: absolute
      }
       .title{
          display: none;
          position: relative /*text will appear on top of image*/
       }
      img:hover{
          opactiy: 0.5;
          border-color: #000;
      }
      img:hover + .title { /*display the tile when hover over the image*/
        display: block;
      }

  }
}

HTML

<div class="projects">
    <div class="item">
        <img src="https://picsum.photos/500/290/?random" alt="Project">
        <div class="title">TITLE</div>
        <a href="#!" class="btn-dark">
          <i class="fab fa-behance"></i>
        </a>
    </div>
</div>

关于html - SCSS overlay display none 还在显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52411895/

相关文章:

jquery - 带有 slicknav 的媒体查询未显示并将我的其他菜单与网页底部的中心对齐

css - Div不会居中

css - 交错无限CSS动画

javascript - void 函数返回值使用 JavaScript

HTML 表格,右对齐单元格(不是内容)

html - 尝试制作菜单分隔符破折号而不是实线

jquery - 带有 Superfish 的菜单 - 链接在 chrome 上不起作用

css - 在某些情况下禁用 stylelint 警告

html - 使用 SCSS 定位我的类(class)时遇到问题

javascript - 获取 HTML Body 中的 Javascript 变量