我有一个菜单,对所有列出的链接/项目都有悬停效果。我想放一个Home图标(房子),其悬停效果可以在两个不同颜色的相同图像之间切换,好吧我得到了这个,但主要的悬停效果仍然适用于它作为背景。
例如,当我将鼠标移动到任何链接上时,悬停效果是文本周围的橙色背景,我想仅从主页图标中删除该效果(已经在白宫和白宫之间切换)鼠标上的橙色房子。)
我尝试了很多事情,但仍然没有成功......
提前谢谢!
Picture of what I'm talking about
HTML code:
<div class="Menu">
<div class="ner">
<ul>
<li class="home">
<a href="#" ><img onmouseout="this.src='home1.png'" onmouseover="this.src='home2.png'" src="home1.png" width=25px; height=25px;></a></li>
<li><a href="#">Item1</a></li>
<li class="drop">
<a href="#">Item2</a>
<div class="dropdownContain">
<div class="dropOut">
<div class="triangle"></div>
<ul>
<li>Blog 1</li>
<li>Blog 2</li>
<li>Blog 3</li>
<li>Blog Blog 4</li>
</ul>
</div>
</div>
</li>
<li><a href="#">Item3</a></li>
<li class="drop">
<a href="#">Item4</a>
<div class="dropdownContain">
<div class="dropOut">
<div class="triangle"></div>
<ul>
<li>Blog 1</li>
<li>Blog 2</li>
<li>Blog Blog 3</li>
<li>Blog Blog 4</li>
</ul>
</div>
</div>
</li>
<li><a href="#">Item5</a></li>
<li><a href="#">Item6</a></li>
</ul>
</div>
</div>
CSS代码:
.Menu {
background: #44474B;
display: block;
position: fixed;
width:900px;
right: 0;
top: 0;
height: 55px;
min-width: 100%;
z-index: 9999;
}
.Menu ul{ float:left;}
.Menu li{position:relative; z-index:10; float:left; list-style:none; margin:0 15px; }
.Menu a{ padding:11px 18px; color:#373737; list-style:none; color:#FFF; text-decoration:none;
-webkit-transition: all .3s linear 0s;
-moz-transition: all .3s linear 0s;
-ms-transition: all .3s linear 0s;
-o-transition: all .3s linear 0s;
transition: all .3s linear 0s;}
.Menu ul li a:hover{ border-radius:6px;
background: #ffa84c; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: -moz-linear-gradient(top, #ffa84c 0%, #ff7b0d 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffa84c), color-stop(100%,#ff7b0d)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #ffa84c 0%,#ff7b0d 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #ffa84c 0%,#ff7b0d 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #ffa84c 0%,#ff7b0d 100%); /* IE10+ */
background: linear-gradient(to bottom, #ffa84c 0%,#ff7b0d 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffa84c', endColorstr='#ff7b0d',GradientType=0 ); /* IE6-8 */
}
.Menu .home a:hover {
background-color: green; !important
text-decoration:none; !important
}
.ner{width:900px; margin:0 auto; padding-top:0; padding-left:0;}
绿色背景色仅供测试之用。
答案 0 :(得分:2)
您可以将一个类添加到主图标的锚标记中,并对该类实现不同的css更改,如下所示:
HTML:
<li>
<a class="home" href="#" ><img onmouseout="this.src='home1.png'" onmouseover="this.src='home2.png'" src="home1.png" width="25" height="25">
</a>
</li>
CSS:
a:hover.home {
background-color: green; !important
text-decoration:none; !important
}
这是一个带有上述代码的jsfiddle示例:http://jsfiddle.net/AndrewL32/g2vqL0ms
width=25px; height=25px;
应为width="25" height="25"