代码之家  ›  专栏  ›  技术社区  ›  lemoncodes

如何正确设置图像悬停时的文字标题

  •  0
  • lemoncodes  · 技术社区  · 8 年前

    Sample Code on StackBlitz

    我一直试图用纯css来实现这一点,以便在我的角度代码中只处理那些数据和屏幕转换(routerlinks)。我把样式设计留给CSS和其他库(即棱角砌体)

    3 回复  |  直到 8 年前
        1
  •  1
  •   user184994    8 年前

    问题是 .feed-header 坐在过滤器后面,所以你需要设置一个 z-index

    .masonry-item
    .feed-container
    .feed-header {
      position: absolute;
      width: 100%;
      padding: 10px;
      align-items: center;
      display: flex;
      z-index: 9;
    }
    

    另外,如果你想让文本对比,你可以设置它为白色悬停(以对比黑暗过滤器)。您可以使用:

    .masonry-item
    .feed-container:hover
    .feed-header {
      color: white;
    }
    

    Here is a StackBlitz demo

        2
  •  0
  •   user4676340 user4676340    8 年前

    This stackblitz should work

    我所做的就是把球顶上 图像并将其作为SASS添加到CSS文件中:

    ngxMasonryItem {
      .feed-text {
        color: white;
        z-index: 9999;
      }
      &:hover {
        img {
          filter:  blur(2px) brightness(50%)
        }
      }
    }
    

    (删除以前使用的过滤器)

    在HTML中,声明顺序很重要,也是如此 z-index

        3
  •  0
  •   harkesh kumar    8 年前

    Try This Demo

    CSS文件

    .box {  
    
        cursor: pointer;  
        height: 468px;  
        float: left;  
        margin: 5px;  
        position: relative;  
        overflow: hidden;  
        width: 468px;  
    
    }  
    
     .box img {  
        position: absolute;  
        left: 0;  
        -webkit-transition: all 300ms ease-out;  
        -moz-transition: all 300ms ease-out;  
        -o-transition: all 300ms ease-out;  
        -ms-transition: all 300ms ease-out;  
        transition: all 300ms ease-out;  
    }  
    
    
    .box .caption {  
        font-family: Tahoma;
        font-size: .5em;
        background-color: rgba(0,0,0,0.8);  
        position: absolute;  
        color: #fff;  
        z-index: 100;  
        -webkit-transition: all 300ms ease-out;  
        -moz-transition: all 300ms ease-out;  
        -o-transition: all 300ms ease-out;  
        -ms-transition: all 300ms ease-out;  
        transition: all 300ms ease-out;  
        left: 0;  
        opacity: 0;  
        width: 450px;  
        height: 450px;  
        text-align: left;  
        padding: 15px;
    }  
    
    
    
     .box:hover .fade-caption {  
        opacity: 1;  
    } 
    

    HTML文件

    <div id="mainwrapper"> 
    
    <!-- Image Caption 3 -->  
         <!-- Image Caption 3 -->  
        <div class="box">  
            <img id="image-3" src="https://www.w3schools.com/howto/img_avatar.png"/>  
            <span class="caption fade-caption">  
            <h3>Fade Caption</h3>  
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit,sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>  
            </span>  
        </div>
    
       <div class="box">  
            <img id="image-3" src="https://www.w3schools.com/howto/img_avatar.png"/>  
            <span class="caption fade-caption">  
            <h3>Fade Caption</h3>  
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit,sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>  
            </span>  
        </div>
    
    
    </div>