生成的源代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <style type="text/css"> a:link { color: #06F; text-decoration: none; } a:visited { color: #999; text-decoration: line-through; } a:hover { color: #F00; text-decoration: underline; } a:active { color: #F0F; } </style> </head> <body> <p><a href="#">这里是链接</a></p> <p><a href="10.html">这里也是链接</a></p> </body> </html> |
注意:四种状态的顺序一定不能颠倒,否则有些不生效
二、将链接转换为块级元素
链接在默认状态下是内联元素,转换为块级元素后可以获得更大的点击区域,可以设置宽度和高度,将链接转换为块状,只需增加一个display:block的css属性即可。
a { display: block; height: 30px; width: 100px; line-height: 30px; text-align: center; background: #CCC; }
这样设置的结果是全局a都执行这个样式显示,下面设置一下鼠标划过时 的状态,其它几种状态设置方法相同