所以我使用混合模式:乘;效果在我的图像之上创建一个多层,当悬停时。问题是图层位于图像边界之外,如下图所示。我尝试将宽度和高度设置为.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>
发布于 2016-10-18 06:17:57
.imgwrapper {
position: relative;
display: inline-block;
}
.imgcon > img{display:block}发布于 2016-10-18 06:28:21
这是你的解决办法。作为解释,在默认情况下,任何块元素都将是其父元素宽度的100%。如果希望元素保持其容器的宽度,则需要使用不同的display属性;在这里,inline-block似乎最有意义。
底部添加的空间是许多元素所拥有的,我称之为下降空间。某些字母如"g“和”j“在文本行下面下垂。dip的部分称为下降器。许多元素为下降器留出了一点空间。要去掉这个空格,可以将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>
发布于 2016-10-18 06:13:58
您所缺少的只是图像的父级上的一个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使其包装到其子级的维度。
https://stackoverflow.com/questions/40100543
复制相似问题