html链接css代码link,CSS 链接(link)

CSS 链接

不同的链接可以有不同的样式。

链接样式

链接的样式,可以用任何CSS属性(如颜色,字体,背景等)。

特别的链接,可以有不同的样式,这取决于他们是什么状态。

这四个链接状态是:a:link - 正常,未访问过的链接

a:visited - 用户已访问过的链接

a:hover - 当用户鼠标放在链接上时

a:active - 链接被点击的那一刻

实例

html>

html教程(html.cn)

a:link {color:#FF0000;}    /* unvisited link */

a:visited {color:#00FF00;} /* visited link */

a:hover {color:#FF00FF;}   /* mouse over link */

a:active {color:#0000FF;}  /* selected link */

这是一个链接

注意: a:hover 必须在 a:link 和 a:visited 之后,需要严格按顺序才能看到效果。

注意: a:active 必须在 a:hover 之后。

运行实例 »

点击 "运行实例" 按钮查看在线实例

当设置为若干链路状态的样式,也有一些顺序规则:a:hover 必须跟在 a:link 和 a:visited后面

a:active 必须跟在 a:hover后面

常见的链接样式

根据上述链接的颜色变化的例子,看它是在什么状态。

让我们通过一些其他常见的方式转到链接样式:

文本修饰

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

实例

html>

html教程(html.cn)

a:link {text-decoration:none;}    /* unvisited link */

a:visited {text-decoration:none;} /* visited link */

a:hover {text-decoration:underline;}   /* mouse over link */

a:active {text-decoration:underline;}  /* selected link */

This is a link

Note: a:hover MUST come after a:link and a:visited in the CSS

definition in order to be effective.

Note: a:active MUST come after a:hover in the CSS definition in order

to be effective.

运行实例 »

点击 "运行实例" 按钮查看在线实例

背景颜色

背景颜色属性指定链接背景色:

实例

html>

html教程(html.cn)

a:link {background-color:#B2FF99;}    /* unvisited link */

a:visited {background-color:#FFFF85;} /* visited link */

a:hover {background-color:#FF704D;}   /* mouse over link */

a:active {background-color:#FF704D;}

a:active {text-decoration:underline;}  /* selected link */

This is a link

注意: hover必须在:link和 a:visited之后定义才有效.

注意:active必须在hover之后定义是有效的.

运行实例 »

点击 "运行实例" 按钮查看在线实例

More Examples

实例

html>

html教程(html.cn)

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;}

将鼠标移至链接上改变样式.

This link changes color

This link changes font-size

This link changes background-color

This link changes font-family

This link changes text-decoration

运行实例 »

点击 "运行实例" 按钮查看在线实例

这个例子演示了如何为超链接添加其他样式。

实例

html>

html教程(html.cn)

a:link,a:visited

{

display:block;

font-weight:bold;

color:#FFFFFF;

background-color:#98bf21;

width:120px;

text-align:center;

padding:4px;

text-decoration:none;

}

a:hover,a:active

{

background-color:#7A991A;

}

This is a link

运行实例 »

点击 "运行实例" 按钮查看在线实例

这个例子演示了一个更高级的例子,我们结合若干CSS属性显示为方框。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值