我在 CSS 中添加了标题类并设置了标题样式。在您的代码中,标题将保留在图像下方。然后我设置position:relative
并设置距离底部20px的位置。我给它一个background-color:red
,以便让您看到它的位置。我还给标题设置了 150 像素的宽度作为图像的宽度。您使用了team
类info
和caption
。为了在每张图片中分别定位鼠标悬停功能,我为每张图片创建了 2 种不同类型的类,所以:team1
, team2
, info1
, info2
, caption1
, caption2
. 如果您想在网页上使用 3 张图片,则必须在 html、css 和 jquery 函数中添加team3
、info3
等。caption3
(您可以复制和粘贴并重命名)。我添加了一个带有 id 的父 divimage
包装每个图像并提供相对定位。您可以根据需要编辑代码。
这是编辑后的 HTML:
<div id="image">
<img src="http://icons.iconarchive.com/icons/tpdkdesign.net/refresh-cl/256/Symbols- Critical-icon.png" class="team1"/>
<div class="info1">"this is a symbol"<BR>"this is a symbol"<BR>"this is a symbol" <BR>"this is a symbol"<BR>"this is a symbol"<BR>"this is a symbol"<BR>"this is a symbol" <BR>"this is a symbol"<BR></div>
<div class="caption1">SYMBOL</div>
</div>
<div id="image">
<img src="http://icons.iconarchive.com/icons/tpdkdesign.net/refresh-cl/256/Symbols- Favourite-1-icon.png" alt="" class="team2"/>
<div class="info2">and this is a star<BR>and this is a star<BR>and this is a star<BR>and this is a star<BR>and this is a star<BR>and this is a star<BR>and this is a star<BR></div>
<div class="caption2">STAR</div>
</div>
</p>
这是编辑后的 CSS:
.team1 {
background: #151515;
height: 150px;
width: 150px;
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.info1{
background: white;
height: 150px;
width: 150px;
visibility:hidden;
position: absolute;
top: 10px;
right: 10px;
}
.team2{
background: #151515;
height: 150px;
width: 150px;
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.info2 {
background: white;
height: 150px;
width: 150px;
visibility:hidden;
position: absolute;
top: 10px;
right: 10px;
}
.team1:hover {
opacity: 0.5;
}
.team2:hover {
opacity: 0.5;
}
.caption1 {
position:relative;
background-color:red;
width:150px;
bottom:20px;
visibility:hidden;
}
.caption2 {
position:relative;
background-color:red;
width:150px;
bottom:20px;
visibility:hidden;
}
#image {
position:relative;
}
</p>
然后我添加了一些 jquery 函数,您可以在其他 html 代码之后将它们放在 html 页面的正文中:
$(".team1").mouseout(function () {
$(".caption1").css("visibility","hidden");
$(".info1").css("visibility","hidden");
});
$(".team1").mouseover(function () {
$(".caption1").css("visibility","visible");
$(".info1").css("visibility","visible");
});
$(".team2").mouseout(function () {
$(".caption2").css("visibility","hidden");
$(".info2").css("visibility","hidden");
});
$(".team2").mouseover(function () {
$(".caption2").css("visibility","visible");
$(".info2").css("visibility","visible");
});
为了使用 jquery 函数,你必须在你的页面中包含 jquery 库,方法是在<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
你的 HTML 页面的头部插入:
<head>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
</head>
这是关于jsfiddle的演示