【问题标题】:Blend mode layer goes outside image border混合模式图层超出图像边界
【发布时间】:2016-10-18 05:54:47
【问题描述】:

所以我使用混合混合模式:乘法;悬停时在我的图像顶部创建多层的效果。问题是图层超出了图像边界,如下图所示。我尝试将宽度和高度设置为 .imgcon 和 .imgcon > img(请参见下面的代码),并且该图层适合,但是当在不同的屏幕分辨率上查看时,它会弄乱响应式 Web 功能。所以我尝试将宽度和高度设置为 100% 以保持响应功能,但图层仍然超出图像边框。

这是我的代码:

.imgwrapper {
  position: relative;
}



.imgcon + div {
 position: absolute;
  left: 42%;
  top: 44%;
  color: white;
  text-decoration: underline;
  opacity:0;
  display: block;
  pointer-events: none;
  font-size: 18px;
  
  letter-spacing: 4px;

}

.imgcon {
 position: relative;
 background: rgba(209, 19, 15, 0);
  transition: ease 0s;
  -webkit-transition: ease 0s;
  -moz-transition: ease 0s;
  -ms-transition: ease 0s;
  -o-transition: ease 0s;
   mix-blend-mode: multiply;
}
.imgcon > img {
 transition: ease 0s;
  -webkit-transition: ease 0s;
  -moz-transition: ease 0s;
  -ms-transition: ease 0s;
  -o-transition: ease 0s;
}
.imgcon:hover {
  background: #b41f24;
    background: rgba(180, 31, 36, 0.85);


}
.imgcon:hover > img {
  z-index: -1;
  -webkit-filter: grayscale(100%) blur(1.5px) contrast(100%);
  filter: grayscale(100%) blur(1.5px) contrast(100%) ;
  mix-blend-mode: multiply;

}

.imgcon:hover + div {
  display: block;
  opacity: 1;
  z-index: 1;
}
<a href="works.html?option=emkoinvite" class="permalink">
					<div class="desktop-3 mobile-half columns">
						<div class="item first-row">
							<h3>EmKO invitation</h3>
							<span class="category">Identity, print</span>

							<div class="imgwrapper">
							<div class="imgcon">
							<img src="http://i.imgur.com/XmhcxJS.png" /></div>
							<div id="view">view</div></div>
						</div><!-- // .item -->
					</div><!-- // .desktop-3 -->
				</a>

【问题讨论】:

    标签: html css image mix-blend-mode


    【解决方案1】:

    这是您的解决方案。作为解释,默认情况下,任何块元素的宽度都是其父元素的 100%。如果您希望元素保持其容器的宽度,则需要使用不同的display 属性; inline-block 似乎在这里最有意义。

    底部增加的空间是很多元素都有的,我称之为下降空间。某些字母如“g”和j”会在文本行下方下降。下降的部分称为下降部分。许多元素为下降部分留出了一点空间。要摆脱这个空间,您可以将line-height设置为0。

    宽度和居中的文本只是让我将文本正确居中的一种更简单的方法。

    如果您有任何其他问题,请告诉我!

    .imgwrapper {
      position: relative;
    }
    
    
    
    .imgcon + div {
     position: absolute;
      text-align: center;
      top: 42%;
      width: 256px;
      color: white;
      text-decoration: underline;
      opacity:0;
      display: block;
      pointer-events: none;
      font-size: 18px;
      
      letter-spacing: 4px;
    
    }
    
    .imgcon {
     position: relative;
     display: inline-block;
     line-height: 0;
     background: rgba(209, 19, 15, 0);
      transition: ease 0s;
      -webkit-transition: ease 0s;
      -moz-transition: ease 0s;
      -ms-transition: ease 0s;
      -o-transition: ease 0s;
       mix-blend-mode: multiply;
    }
    .imgcon > img {
     transition: ease 0s;
      -webkit-transition: ease 0s;
      -moz-transition: ease 0s;
      -ms-transition: ease 0s;
      -o-transition: ease 0s;
    }
    .imgcon:hover {
      background: #b41f24;
        background: rgba(180, 31, 36, 0.85);
    
    
    }
    .imgcon:hover > img {
      z-index: -1;
      -webkit-filter: grayscale(100%) blur(1.5px) contrast(100%);
      filter: grayscale(100%) blur(1.5px) contrast(100%) ;
      mix-blend-mode: multiply;
    
    }
    
    .imgcon:hover + div {
      display: block;
      opacity: 1;
      z-index: 1;
    }
    <a href="works.html?option=emkoinvite" class="permalink">
    					<div class="desktop-3 mobile-half columns">
    						<div class="item first-row">
    							<h3>EmKO invitation</h3>
    							<span class="category">Identity, print</span>
    
    							<div class="imgwrapper">
    							<div class="imgcon">
    							<img src="http://i.imgur.com/XmhcxJS.png" /></div>
    							<div id="view">view</div></div>
    						</div><!-- // .item -->
    					</div><!-- // .desktop-3 -->
    				</a>

    【讨论】:

      【解决方案2】:
      .imgwrapper {
          position: relative;
          display: inline-block;
      }
      
      .imgcon > img{display:block}
      

      【讨论】:

        【解决方案3】:

        您所缺少的只是图像父级上的display: inline-block;

        .imgwrapper {
          position: relative;
        }
        .imgcon + div {
         position: absolute;
          left: 42%;
          top: 44%;
          color: white;
          text-decoration: underline;
          opacity:0;
          display: block;
          pointer-events: none;
          font-size: 18px;
          letter-spacing: 4px;
        }
        .imgcon {
         display: inline-block;
         position: relative;
         background: rgba(209, 19, 15, 0);
          transition: ease 0s;
          -webkit-transition: ease 0s;
          -moz-transition: ease 0s;
          -ms-transition: ease 0s;
          -o-transition: ease 0s;
           mix-blend-mode: multiply;
        }
        .imgcon > img {
         transition: ease 0s;
          -webkit-transition: ease 0s;
          -moz-transition: ease 0s;
          -ms-transition: ease 0s;
          -o-transition: ease 0s;
        }
        .imgcon:hover {
          background: #b41f24;
          background: rgba(180, 31, 36, 0.85);
        }
        .imgcon:hover > img {
          z-index: -1;
          -webkit-filter: grayscale(100%) blur(1.5px) contrast(100%);
          filter: grayscale(100%) blur(1.5px) contrast(100%) ;
          mix-blend-mode: multiply;
        }
        .imgcon:hover + div {
          display: block;
          opacity: 1;
          z-index: 1;
        }
        <a href="works.html?option=emkoinvite" class="permalink">
        					<div class="desktop-3 mobile-half columns">
        						<div class="item first-row">
        							<h3>EmKO invitation</h3>
        							<span class="category">Identity, print</span>
        							<div class="imgwrapper">
        							<div class="imgcon">
        							<img src="http://i.imgur.com/XmhcxJS.png" /></div>
        							<div id="view">view</div></div>
        						</div><!-- // .item -->
        					</div><!-- // .desktop-3 -->
        				</a>

        这是因为父元素是一个 div,因此它是一个块元素并占用所有可用宽度。将它的 display 更改为 inline-block 使其 wrap 到它的孩子的尺寸。

        【讨论】:

        • 谢谢,但图层仍然在图像底部渗出约 2 个像素。知道为什么吗?
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-11-29
        • 1970-01-01
        • 2023-01-21
        • 2016-01-24
        • 1970-01-01
        • 2017-04-13
        • 2014-07-22
        相关资源
        最近更新 更多