【发布时间】:2011-09-29 12:25:22
【问题描述】:
我正在尝试构建一个带有缩略图和显示更大图像的图片库。目前,当鼠标悬停在显示较大图像的缩略图上时,它的工作。但是,我希望用单击替换悬停功能,以便在鼠标离开缩略图时较大的图像不会消失。通过一些研究,我相信这不能像悬停功能那样使用 css 来完成,我需要包含一些脚本。由于在此之后我是 Web 开发的新手,所以我有点迷茫,希望能得到一些帮助。下面是gallery容器的html代码和对应的css代码......从这里开始呢?
谢谢 一个
html代码
<div class="gallerycontainer">
<a class="thumbnail" href="#thumb"><img src="images/gallery/1one/101.jpg" width="56px" height="80px" border="0" /><span><img src="images/gallery/1one/101.jpg" width="405px" height="585px"/></span></a>
<a class="thumbnail" href="#thumb"><img src="images/gallery/1one/102.jpg" width="56px" height="80px" border="0" /><span><img src="images/gallery/1one/102.jpg" width="405px" height="585px"/></span></a>
<a class="thumbnail" href="#thumb"><img src="images/gallery/1one/103.jpg" width="56px" height="80px" border="0" /><span><img src="images/gallery/1one/103.jpg" width="405px" height="585px"/></span></a>
<a class="thumbnail" href="#thumb"><img src="images/gallery/1one/104.jpg" width="56px" height="80px"border="0" /><span><img src="images/gallery/1one/104.jpg" width="405px" height="585px"/></span></a>
<br />
</div>
css代码
.gallerycontainer{
position: absolute;
/*Add a height attribute and set to largest image's height to prevent overlaying*/
}
.thumbnail img{
border: 1px solid white;
margin: 0 5px 5px 0;
}
.thumbnail:hover{
background-color: transparent;
}
.thumbnail:hover img{
border: 1px solid grey;
}
.thumbnail span{ /*CSS for enlarged image*/
position: absolute;
background-color: #000000;
padding: 5px;
left: -1000px;
border: none;
visibility: hidden;
color: black;
text-decoration: none;
}
.thumbnail span img{ /*CSS for enlarged image*/
border-width: 0;
padding: 2px;
}
.thumbnail:hover span{ /*CSS for enlarged image*/
visibility: visible;
top: 0;
left: 300px; /*position where enlarged image should offset horizontally */
z-index: 50;
}
【问题讨论】:
-
下次请使用代码功能,否则您的代码将无法正确显示在屏幕上。
标签: html css gallery thumbnails