前端必知必会-css链接Links


CSS 链接Links

使用 CSS,链接可以采用多种不同的样式。

样式化链接

可以使用任何 CSS 属性(例如颜色、字体系列、背景等)来设置链接样式。

示例

a {
color: hotpink;
}

此外,链接可以根据其所处的状态采用不同的样式。

四种链接状态为:

  • a:link - 普通、未访问的链接
  • a:visited - 用户已访问的链接
  • a:hover - 用户将鼠标悬停在链接上时的链接
  • a:active - 单击链接时的链接

示例

/* 未访问的链接 */
a:link {
color: red;
}

/* 已访问的链接 */
a:visited {
color: green;
}

/* 鼠标悬停在链接上 */
a:hover {
color: hotpink;
}

/* 选定的链接 */
a:active {
color: blue;
}

在为多个链接状态设置样式时,有一些顺序规则:

a:hover 必须在 a:link 和 a:visited 之后
a:active 必须在 a:hover 之后

文本装饰text-decoration

text-decoration 属性主要用于从链接中删除下划线:

示例

a:link {
text-decoration: none;
}

a:visited {
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

a:active {
text-decoration: underline;
}

背景颜色background-color

background-color 属性可用于指定链接的背景颜色:

示例

a:link {
background-color: yellow;
}

a:visited {
background-color: cyan;
}

a:hover {
background-color: lightgreen;
}

a:active {
background-color: hotpink;
}

链接Links按钮

示例

a:link, a:visited {
background-color: #f44336;
color: white;
padding: 14px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
}

a:hover, a:active {
background-color: red;
}

向超链接添加其他样式示例

a.one:link {color: #ff0000;}
a.one:visited {color: #0000ff;}
a.one:hover {color: #ffcc00;}

a.two:link {color: #ff0000;}
a.two:visited {color: #0000ff;}
a.two:hover {font-size: 150%;}

a.three:link {color: #ff0000;}
a.three:visited {color: #0000ff;}
a.three:hover {background: #66ff66;}

a.four:link {color: #ff0000;}
a.four:visited {color: #0000ff;}
a.four:hover {font-family: monospace;}

a.five:link {color: #ff0000; text-decoration: none;}
a.five:visited {color: #0000ff; text-decoration: none;}
a.five:hover {text-decoration: underline;}
示例
另一个如何创建链接框/按钮的示例:

a:link, a:visited {
background-color: white;
color: black;
border: 2px solid green;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
}

a:hover, a:active {
background-color: green;
color: white;
}

不同类型的光标示例(可用于链接):

<span style="cursor: auto">auto</span><br>
<span style="cursor: crosshair">crosshair</span><br>
<span style="cursor: default">default</span><br>
<span style="cursor: e-resize">e-resize</span><br>
<span style="cursor: help">help</span><br>
<span style="cursor: move">move</span><br>
<span style="cursor: n-resize">n-resize</span><br>
<span style="cursor: ne-resize">ne-resize</span><br>
<span style="cursor: nw-resize">nw-resize</span><br>
<span style="cursor: pointer">pointer</span><br>
<span style="cursor:进度">进度</span><br>
<span style="cursor: s-resize">s-resize</span><br>
<span style="cursor: se-resize">se-resize</span><br>
<span style="cursor: sw-resize">sw-resize</span><br>
<span style="cursor: text">文本</span><br>
<span style="cursor: w-resize">w-resize</span><br>
<span style="cursor: wait">等待</span>

总结

本文介绍了的使用,如有问题欢迎私信和评论

  • 8
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程岁月

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值