HTML
<article id="articlebottom">
<div class="products">
<div class="imgWrap">
<img src="http://t0.gstatic.com/images?q=tbn:ANd9GcTA1uJ8WQ7fiJ2cbdoMph39XIJYQztt6FWoxfkk32gwnOz0qcmjyg" alt="candle" />
<p class="imgDescription">Camphor</p>
</div>
<div class="imgWrap">
<img src="http://t0.gstatic.com/images?q=tbn:ANd9GcTA1uJ8WQ7fiJ2cbdoMph39XIJYQztt6FWoxfkk32gwnOz0qcmjyg" alt="candle" />
<p class="imgDescription">Camphor</p>
</div>
<div class="imgWrap">
<img src="http://t0.gstatic.com/images?q=tbn:ANd9GcTA1uJ8WQ7fiJ2cbdoMph39XIJYQztt6FWoxfkk32gwnOz0qcmjyg" alt="candle" />
<p class="imgDescription">Camphor</p>
</div>
</div>
</article>
CSS
#articlebottom {
width: 980px;
height: 300px;
}
.products
{
width:980px;
margin:0px auto;
padding-left:20px;
}
#articlebottom .imgWrap img {
margin:0px;
padding:0px;
width:295px;
float:left;
margin:10px;
height:200px;
border:5px solid #000;
}
#articlebottom .imgDescription {
position: absolute;
padding-top:35px;
letter-spacing: 2px;
background-color: rgba(255, 250, 250, 0.2);
color: #1b9bff;
font-weight:bold;
font-size:18pt;
width:310px;
height:50px;
opacity: 1;
text-align:center;
visibility: hidden;
opacity: 100;
text-transform:uppercase;
/*-webkit-transition: visibility opacity 0.2s;*/
}
#articlebottom .imgWrap:hover .imgDescription {
visibility: visible;
}
我有什么:
我需要什么:
我的设计出现问题:
即使我将鼠标悬停在第二张图像上,文字也只显示在第一张图片上。!!
答案 0 :(得分:3)
使用绝对位置时,请确保该元素的父级具有相对位置:
*{/*reset*/
padding:0;
margin:0;
}
#articlebottom {
width: 980px;
height: 300px;
}
.products{
width:980px;
margin:0px auto;
padding-left:20px;
}
#articlebottom .imgWrap {
width:295px;
height:200px;
position:relative;/* set .imgWrap to relative to be able to use position absolute on childrens*/
float:left;
margin:10px;
border:5px solid #000;
}
#articlebottom .imgWrap img {
width:100%;
height:100%;
}
#articlebottom .imgDescription {
position: absolute;
top:35px;
left:0;
letter-spacing: 2px;
background-color: rgba(255, 250, 250, 0.2);
color: #1b9bff;
font-weight:bold;
font-size:18pt;
width:100%;
height:50px;
opacity: 1;
text-align:center;
visibility: hidden;
opacity: 100;
text-transform:uppercase;
/*-webkit-transition: visibility opacity 0.2s;*/
}
#articlebottom .imgWrap:hover .imgDescription {
visibility: visible;
}
答案 1 :(得分:0)
我刚用@kougiland解决方案,您需要将透明背景高度设置为图像高度
<强> CSS 强>
*{
padding:0;
margin:0;
}
#articlebottom {
width: 980px;
height: 300px;
}
.products{
width:980px;
margin:0px auto;
padding-left:20px;
}
#articlebottom .imgWrap {
width:295px;
height:200px;
position:relative;
float:left;
margin:10px;
background:black;
}
#articlebottom .imgWrap img {
position:absolute;
left:5px;
top:5px;
width:285px;
height:190px;
}
#articlebottom .imgDescription {
position: absolute;
left:0;
letter-spacing: 2px;
background-color: rgba(255, 250, 250, 0.2);
color: rgba(255, 250, 250, 0.2);
font-weight:bold;
font-size:18pt;
line-height: 50px;
width:100%;
height:25%;
opacity: 0;
text-align:center;
text-transform:uppercase;
transition:opacity 500ms ease-in-out, color 20ms ease-in-out,height 500ms ease-in-out;
}
#articlebottom .imgWrap:hover .imgDescription {
opacity: 1;
height:100%;
color: #1b9bff;
}