使用 CSS 移除链接的默认下划线

cssweb developmentfront end technology更新于 2025/2/2 8:12:17

默认情况下,HTML 中的所有链接都带有下划线。我们可以使用 CSS 的 text-decoration 属性移除此下划线。

语法

CSS text-decoration 属性的语法如下 −

Selector {
   text-decoration: /*value*/
}

示例

以下示例说明了 CSS 文本装饰属性。

<!DOCTYPE html>
<html>
<head>
<style>
p {
   padding: 5px;
   box-shadow: inset 0 0 5px violet;
}
a {
   font-style: italic;
   text-decoration: none;
}
</style>
</head>
<body>
<a href="#">Demo</a>
<p>
<a href="https://example.com/">Example domain</a>
</p>
</body>
</html>

输出

这将给出以下输出 −

示例

<!DOCTYPE html>
<html>
<head>
<style>
div {
   margin: auto;
   width: 50%;
   text-align: right;
   color: green;
   border: thin dashed red;
}
a {
   text-decoration: none;
}
a:last-child {
   color: inherit;
   background-color: moccasin;
}
</style>
</head>
<body>
<div>
<a href="#">Link Demo</a>
<p>
Watch this: <a href="https://example.com/">Example site</a>
</p>
</div>
</body>
</html>

输出

这将给出以下输出 −


相关文章


有用资源