【发布时间】:2014-10-07 21:54:10
【问题描述】:
我正在使用包含图像和标题的“框”(实际上是列表元素)进行导航。通过将鼠标悬停在它上面,盒子会收到一个阴影,以更好地突出盒子。单击后,我希望以相同的方式突出显示该框。
我设法让一个小的 jQuery 脚本以这种方式工作,只有部分 CSS。 CSS 有点缺陷,我看不出如何使它正常工作。这是代码下方的a fiddle。 “.active”类位于 CSS 列表的底部。
<div class="explore">
<div class="explore_body">
<ul id="nav">
<li><a href="#!" ><img src="http://geg.informea.org/wp-content/themes/geg/images/air_pollution.png" /></a><a href="#!" class="album_title">Air pollution and air quality</a></li>
<li><a href="#!" ><img src="http://geg.informea.org/wp-content/themes/geg/images/biodiversity.png"/></a><a href="#!" class="album_title">Biodiversity</a></li>
</ul>
</div>
</div>
CSS: 。探索 { 左边距:自动; 边距右:自动; 宽度:70%; 边距顶部:20px; }
.explore_body {
width: 100%;
/* border: 1px solid #f00; */
padding-bottom: 5px;
padding-top: 5px;
clear: both;
background: #F4F4F4;
*background: #F4F4F4; /* star hack to target IE6 & 7*/
}
.explore_body ul {
margin: 5px;
padding-top: 5px;
clear: both;
width: 100%;
}
.explore_body ul li {
display: inline-block; /*IE7 doesn't support inline-block */
zoom: 1;
*display: inline; /* star hack to target IE6 & 7*/
/* background: url(images/album.png); */
width: 130px;
height: 145px;
margin: 5px 5px;
}
.explore_shadow {
width: 100%;
height: 20px;
/* background: url(images/explore_shadow.png) no-repeat; */
}
.explore_body ul li img {
width: 120px;
height: 100px;
margin: 5px 0px 5px 5px;
}
.explore_body ul li {
opacity: 0.9;
filter:alpha(opacity=90); /* For IE8 and earlier */
}
.explore_body ul li:hover {
opacity: 1;
filter:alpha(opacity=100); /* For IE8 and earlier */
-webkit-box-shadow: 3px 3px 3px 3px #666;
}
.explore_body ul li:selected {
opacity: 1;
filter:alpha(opacity=100); /* For IE8 and earlier */
-webkit-box-shadow: 3px 3px 3px 3px #666;
}
.album_title {
display: inline-block;
float: left;
margin-top: 0px;
margin-left: 5px;
color: #3c72d2;
font-weight: bold;
max-width: 140px;
text-align: left;
clear: both;
}
.album_title:hover {
color: #1F3D6F;
}
.active {
display: inline-block; /*IE7 doesn't support inline-block */
zoom: 1;
*display: inline; /* star hack to target IE6 & 7*/
/* background: url(images/album.png); */
width: 130px;
height: 135px;
opacity: 1;
filter:alpha(opacity=100); /* For IE8 and earlier */
-webkit-box-shadow: 3px 3px 3px 3px #666;
}
jQuery:
$(function () {
$("#nav li a").click(function (e) {
e.preventDefault();
$("#nav li a").addClass("active").not(this).removeClass("active");
});
});
感谢您在找出正确的 CSS 方面的任何帮助。
【问题讨论】: