在我的网站上,我在家中有4个标签,名为假日好客活动,咨询。我正在尝试的是悬停我希望显示图像的选项卡。我试过这样的。
我的HTML:
<div class="menu_links">
<div style="margin-left:40px;width:150px;height:33px;-webkit-border-radius: 50px;-moz-border-radius: 50px;border-radius: 50px;border:3px solid #CC9900;background-color:#FFD630;"> <a href="javascript:void(0);"><b>H</b>olidays</a>
</div>
</div>
<div class="menu_links">
<div style="margin-left:40px;width:150px;height:33px;-webkit-border-radius: 50px;-moz-border-radius: 50px;border-radius: 50px;border:3px solid #CC9900;background-color:#FFD630;"> <a href="javascript:void(0);"><b>H</b>ospitality</a>
</div>
</div>
<div class="menu_links">
<div style="margin-left:40px;width:150px;height:33px;-webkit-border-radius: 50px;-moz-border-radius: 50px;border-radius: 50px;border:3px solid #CC9900;background-color:#FFD630;"> <a href="javascript:void(0);"><b>E</b>vents</a>
</div>
</div>
<div class="menu_links">
<div style="margin-left:40px;width:150px;height:33px;-webkit-border-radius: 50px;-moz-border-radius: 50px;border-radius: 50px;border:3px solid #CC9900;background-color:#FFD630;"> <a href="javascript:void(0);"><b>C</b>onsultant</a>
</div>
</div>
我的css:
.menu_links {
height:85px;
width:250px;
float:left;
margin:5px 0px 0px 0px;
}
.menu_links a {
float:left;
width:150px;
margin:5px 0px 0px 0px;
padding:0px 0px 0px 0px;
text-align:center;
color:#000000;
text-decoration:none;
}
.menu_links:hover {
width:250px;
height:183px;
top:50px;
background: #FF9933;
font-size:25px;
z-index:9999;
background-image:url('../images/holidays_bg.jpg');
}
答案 0 :(得分:1)
您可以使用comb css为每个div分配单独的图像:
.menu_links:hover {background-image:url('../images/holidays_bg.jpg');}
.menu_links + .menu_links:hover {background-image:url('../images/holidays_bg.jpg');}
.menu_links + .menu_links + .menu_links:hover {background-image:url('../images/holidays_bg.jpg');}
.menu_links + .menu_links + .menu_links + .menu_links:hover {background-image:url('../images/holidays_bg.jpg');}
答案 1 :(得分:1)
这个概念是为每个菜单项添加另一个类,每个菜单项都有唯一的名称,并使用这些类分别为每个菜单设置背景属性。
这是您的代码
<div class="menu_links first">
<div style="margin-left:40px;width:150px;height:33px;-webkit-border-radius: 50px;-moz-border-radius: 50px;border-radius: 50px;border:3px solid #CC9900;background-color:#FFD630;">
<a href="javascript:void(0);"><b>H</b>ospitality</a>
</div>
</div>
<div class="menu_links second">
<div style="margin-left:40px;width:150px;height:33px;-webkit-border-radius: 50px;-moz-border-radius: 50px;border-radius: 50px;border:3px solid #CC9900;background-color:#FFD630;">
<a href="javascript:void(0);"><b>E</b>vents</a>
</div>
</div>
<div class="menu_links third">
<div style="margin-left:40px;width:150px;height:33px;-webkit-border-radius: 50px;-moz-border-radius: 50px;border-radius: 50px;border:3px solid #CC9900;background-color:#FFD630;">
<a href="javascript:void(0);"><b>C</b>onsultant</a>
</div>
现在相应的css将用于悬停:
除了悬停的css
之外,所有css都将保持不变.first:hover{ width:250px; height:183px; top:50px; background: #FF9933; font-size:25px; z-index:9999; background-image:url('../images/holidays_bg.jpg');}
.second:hover{ width:250px; height:183px; top:50px; background: #BB7733; font-size:25px; z-index:9999; background-image:url('../images/holidays_bg.jpg');}
.third:hover{ width:250px; height:183px; top:50px; background: #557733; font-size:25px; z-index:9999; background-image:url('../images/holidays_bg.jpg');}
你可以在这里检查:: FIDDLE
答案 2 :(得分:1)
html side :
<ul class="menu_links">
<li class="holi"> <a href="holidays.html"><b>H</b>olidays</a>
</li>
<li class="hospi"> <a href="hospitaliy.html"><b>H</b>ospitality</a>
</li>
<li class="events"> <a href="events.html"><b>E</b>vents</a>
</li>
<li class="consult"> <a href="consultant.html"><b>C</b>onsultant</a>
</li>
</ul>
和css方
ul.menu_links {
overflow:auto;
list-style-type:none
}
.menu_links li a {
float:left;
width:100px;
display:block;
background:orange none scroll repeat 0 bottom;
font-family:Trebuchet MS;
color:black;
text-decoration:none;
margin:2px 5px;
padding:10px;
text-align:center
}
.menu_links li a:hover {
color:#444
}
.menu_links li.holi a:hover {
background-image:url(http://lorempixel.com/150/50/abstract/);
}
.menu_links li.hospi a:hover {
background-image:url(http://lorempixel.com/150/50/cats/);
}
.menu_links li.events a:hover {
background-image:url(http://lorempixel.com/150/50/people/);
}
.menu_links li.consult a:hover {
background-image:url(http://lorempixel.com/150/50/sports/);
}
在jsfiddle中查看:http://jsfiddle.net/gJx25/