如何通过CSS使HTML中的链接在鼠标悬停时变色且去除下划线?
你需要查看:hover伪类选择器,color属性和text-decoration属性。
a:hover { color: red; text-decoration: none; }
为确保超链接按照您的意愿进行样式设置(并避免与其他样式规则发生冲突),请使用 !important
:a:hover { color: red !important; text-decoration: none !important; }
除了stragers的回答之外,还要确保以LoVe HAte的方式声明伪类。您必须先声明:link,然后是:visited,然后是:hover,最后是:active。否则,某些浏览器可能不会应用伪类。
a:link{ /*这只适用于有名称的锚点*/ } a:visited{ /*已访问链接的可能样式*/ } a:hover{ /*当鼠标悬停在a标签上时*/ text-decoration:none; color:red; } a:active{ /*当单击a标签时的可能样式*/ }