我想要我的< a>标记在悬停时变为下划线,我使用此代码,但在悬停时没有下划线.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!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"> a.hover:hover {text-decoration: underline;} </style> </head> <body> <form id="form1" runat="server"> <div> <a class="hover" style=" text-decoration:none; color:red" href="">Site Map</a> </div> </form> </body> </html>
这个:
a:hover {text-decoration: underline;} <a style=" text-decoration:none; color:red" href="">Site Map</a>
也不起作用.
我该怎么办?问题是什么?
提前致谢.
解决方法
style属性比任何选择器都多
specific,所以它总是会在级联中最后应用(可怕的!重要规则不能承受).将CSS移动到样式表.
a.hover { color: red; text-decoration: none; } a.hover:hover { text-decoration: underline; }
(我还建议为该类提供更多的语义名称).