问题
<%@ Page Language="C#" AutoEventWireup="true" Theme="SF" CodeBehind="ULLITest.aspx.cs" Inherits="ClickDoors_WebApp.ULLITest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
#Menu
{
padding:0;
margin:0;
list-style-type:none;
font-size:13px;
color:#717171;
width:100%;
}
#Menu li
{
border-bottom:1px solid #eeeeee;
padding:7px 10px 7px 10px;
}
#Menu li:hover
{
color:White;
background-color:#ffcc00;
}
#Menu a:link
{
color:#717171;
text-decoration:none;
}
#Menu a:hover
{
color:White;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<ul id="Menu">
<li><a href="#">Internal Doors</a></li>
<li><a href="#">Prefinished Internal Doors</a></li>
<li><a href="#">External Doors</a></li>
<li><a href="#">Internal Pair [French Doors]</a></li>
<li><a href="#">External Pair [French Doors]</a></li>
<li><a href="#">Custom Size Doors</a></li>
<li><a href="#">Door Frames</a></li>
<li>Test</li>
</ul>
</div>
</form>
</body>
</html>
When i hover over it background-color is changed immediately but font color remains same until i hover over text.
In short i want my menu to behave similar to stackoverflows menu (Questions Tags Users....)
Any help will be appreciated.
回答1:
I'd do it like this:
Set your
<a>
tags todisplay:block
Remove the padding from your
<li>
's (make itpadding:0px
)Re-add the padding to your
<a>
tagspadding:7px 10px 7px 10px;
Add
background-color:#ffcc00;
to#Menu a:hover
Get rid of
#Menu li:hover
回答2:
need to add #Menu li:hover a {color:White;}
This will set white color for a
when a li
is hovered.
Demo: http://jsfiddle.net/Nceef/
回答3:
Give this css properties:
#Menu a {display:block}
#Menu a:hover,active {color:#text-color;background:#background-color;}
回答4:
#Menu li
{
border-bottom:1px solid #eeeeee;
}
#Menu li a:hover
{
color:White;
background-color:#ffcc00;
}
#Menu a:link
{
color:#717171;
text-decoration:none;
display:block;
padding: 7px 10px;
}
Only drawback of this method is your elements in the list that arent anchors wont be padded correctly.
Demo
http://jsfiddle.net/loktar/F6UGv/
来源:https://stackoverflow.com/questions/5156094/css-ul-li-vertical-menu