如何仅使用 CSS 显示链接?
要禁用任何网站的链接,我们使用 CSS 的属性,例如将 pointer-event 设置为 none,然后光标可以设置为默认值,这将禁用活动链接,用户无法访问链接。有时需要禁用链接以对网站进行一些更新或安全措施。政府或组织最适合此示例,每当他们需要对网站后端进行任何更新时,他们只需禁用链接。
在本文中,我们将展示如何仅使用 CSS 显示链接。
语法
<a href="link_of_any_website" class="class_name"></a>
这是一个锚标记,用于表示站点的链接。class_name 是一个属性,用于定义特定元素的 CSS 属性。
使用的属性
示例中使用的属性如下:
color - 定义文本的颜色。
opacity - 定义 HTML 中文本或图像的透明度级别。
text-decoration - 定义添加到文本的装饰,例如下划线、上划线、删除线、下划线上划线和无。
pointer-event - 定义元素如何响应事件。例如 - 链接是否处于活动状态或非活动状态。
cursor - 定义鼠标在指向任何链接时移动。
font-weight - 定义文本粗细。
示例
在此示例中,我们使用了两个名为 active 和 not-active 的类。非活动类设置名为 pointer-event 的属性,这将禁用锚元素中使用的链接,但在活动类中,链接已启用。
<!DOCTYPE html>
<html>
<title>Tutorialspoint</title>
<head>
<style>
h1{
color: darkgreen;
}
.not-active{
opacity: 0.6;
text-decoration: none;
pointer-events: none;
cursor: default;
color: blue;
font-weight: bold;
}
.active{
opacity: 0.6;
text-decoration: none;
color: blue;
font-weight: bold;
}
</style>
</head>
<body>
<center>
<h1>Tutorialspoint</h1>
<h3 style="color: green">(www.tutorialspoint.com)</h3>
<p>The Disable link:
<a href="https://tutorialspoint.com" class="not-active">Click Here</a>
</p>
<p>The Enable link:
<a href="https://tutorialspoint.com" class="active">Click Here</a>
</p>
</center>
</body>
</html>
结论
我们了解了通过使用 CSS 的一些属性在 CSS 中禁用和启用链接之间的区别。要禁用链接,我们已将名为 not-active 的类的一些属性(如指针和文本装饰)的值设置为 none。因此,仅使用 CSS 即可禁用链接。
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP