链接默认带下划线源于浏览器内置样式,可通过a{text-decoration:none}统一去除;如需悬停提示则配合a:hover{text-decoration:underline};注意继承与优先级问题,并建议同步设置color和cursor提升可访问性。
链接默认带下划线,是因为浏览器内置样式设置了 text-decoration: underline。要去掉它,只需在 CSS 中将该属性设为 none。
对所有链接统一去下划线:
a {
text-decoration: none;
}
这样会移除所有 标签的下划线,包括未访问、已访问、悬停和点击状态。
如果只想去掉默认下划线,但保留悬停时的提示效果,可以单独设置 hover 状态:
a { text-decoration: none; }
a:hover { text-decoration: underline; }
a:visited { text-decoration: none; }
如果下划线没消失,可能是其他 CSS 规则优先级更高,或父元素设置了 text-decoration(它会继承)。解决方法:
.nav a 或 #header a
text-decoratio
n: underline(如 p 或 div),因为该属性可继承!important 强制覆盖(不推荐频繁使用):a { text-decoration: none !important; }
去掉下划线后,链接可能不易识别。建议同步调整:
a { color: #007bff; }
a:hover { color: #0056b3; }
a { cursor: pointer; }