【发布时间】:2013-04-01 03:27:03
【问题描述】:
我正在尝试在相当复杂的布局上创建悬停效果。悬停效果有效,但悬停时背景(或覆盖)会超出图像(我希望它与图像一样大)。
有谁知道这是为什么以及如何解决它?
HTML
<article>
<div class="img-crop">
<a href="#" class="title-anchor"><h2>Title</h2></a>
<a href="#"><img src="http://bit.ly/gUKbAE" /></a>
</div>
</article>
CSS
* {
box-sizing: border-box;
-moz-box-sizing: border-box;
}
article {
overflow: hidden;
}
.title-anchor {
display: inline-block;
position: absolute;
overflow: hidden;
z-index: 1;
width: 100%;
height: 100%;
}
.img-crop:hover .title-anchor {
background: rgba(0,0,0,0.5);
}
.img-crop {
display: inline-block;
position: relative;
overflow: hidden;
max-width: 100%;
margin: 0;
padding: 0;
}
h2 {
color: rgba(0,0,0,0);
margin: 0;
padding: 0;
z-index: 2;
line-height: 0;
position: absolute;
top: 50%;
left: 0;
width: 100%;
text-align: center;
}
.img-crop:hover h2 {
color: black;
}
【问题讨论】:
-
我不认为这是任何边距或填充,因为我已经禁用了它们并且效果仍然存在。
-
你不是已经在stackoverflow.com/questions/15904693问过这个问题了
-
@xec,我解决了我之前的问题,但无法弄清楚这一点。在我看来,这是一个不同的问题,尽管在某种程度上是前一个问题的一部分。如果你愿意,你可以删除我之前的问题。
标签: html css image header hover