首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >混合模式层在图像边界外

混合模式层在图像边界外
EN

Stack Overflow用户
提问于 2016-10-18 05:54:47
回答 3查看 104关注 0票数 0

所以我使用混合模式:乘;效果在我的图像之上创建一个多层,当悬停时。问题是图层位于图像边界之外,如下图所示。我尝试将宽度和高度设置为.imgcon和.imgcon > img (请参阅下面的代码),这一层符合要求,但当在不同的屏幕分辨率上查看时,它会扰乱响应性web功能。所以我试着把宽度和高度保持在100%,以保持响应功能,但图层仍然超出图像边界。

这是我的代码:

代码语言:javascript
复制
.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;
}
代码语言:javascript
复制
<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>

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-10-18 06:17:57

代码语言:javascript
复制
.imgwrapper {
    position: relative;
    display: inline-block;
}

.imgcon > img{display:block}
票数 1
EN

Stack Overflow用户

发布于 2016-10-18 06:28:21

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

底部添加的空间是许多元素所拥有的,我称之为下降空间。某些字母如"g“和”j“在文本行下面下垂。dip的部分称为下降器。许多元素为下降器留出了一点空间。要去掉这个空格,可以将line-height设置为0。

宽度和中间的文本内容只是一个更容易的方式,我正确地居中文本。

如果你还有其他问题,请告诉我!

代码语言:javascript
复制
.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;
}
代码语言:javascript
复制
<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
EN

Stack Overflow用户

发布于 2016-10-18 06:13:58

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

代码语言:javascript
复制
.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;
}
代码语言:javascript
复制
<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使其包装到其子级的维度。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40100543

复制
相关文章

相似问题

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