如何删除锚点(链接)的下划线?

本文探讨了如何使用CSS去除HTML锚点(链接)的下划线,包括在样式表中添加规则,避免内联CSS,以及在特定情况下使用更具体的CSS选择器来覆盖默认样式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文翻译自:How to remove the underline for anchors(links)?

无论如何(在CSS中)是为了避免页面中引入的文本和链接的下划线..?


#1楼

参考:https://stackoom.com/question/8z3C/如何删除锚点-链接-的下划线


#2楼

The simplest option is this: 最简单的选择是:

<a style="text-decoration: none">No underline</a>

Of course, mixing CSS with HTML (ie inline CSS) is not a good idea, especially when you are using a tags all over the place. 当然,混合HTML(即内嵌CSS)CSS是不是一个好主意,尤其是当你使用a标签所有的地方。
That's why it's a good idea to add this to a stylesheet instead: 这就是为什么将它添加到样式表中是个好主意:

a {
    text-decoration: none;
}

Or even this code in a JS file: 甚至这个代码在JS文件中:

var els = document.getElementsByTagName('a');

for (var el = 0; el < els.length; el++) {
    els[el].style["text-decoration"] = "none";
}

#3楼

Sometime it will override by some rendering UI CSS. 有时它会被一些渲染UI CSS覆盖。 Better to use: 更好用:

a.className {
    text-decoration: none !important;
}

#4楼

Use CSS to remove text-decoration s. 使用CSS删除text-decoration

a {
    text-decoration: none;
}

#5楼

The css is css是

text-decoration: none;

and

text-decoration: underline;

#6楼

Use CSS. 使用CSS。 this removes underlines from a and u elements: 这将删除au元素的下划线:

a, u {
    text-decoration: none;
}

Sometimes you need to override other styles for elements, in which case you can use the !important modifier on your rule: 有时您需要覆盖元素的其他样式,在这种情况下,您可以在规则上使用!important修饰符:

a {
    text-decoration: none !important;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值