正 文

让网页超链接拥有多姿多彩的下划线


www.7dspace.com  更新日期:2005-8-16 5:08:55  七度空间


  CSS本身没有直接提供变换HTML链接下划线的功能,但只要运用一些技巧,我们还是可以让单调的网页链接下划线变得丰富多彩。

  一、基本原理

  首先,自定义HTML链接下划线的第一步是创建一个图形,在水平方向重复放置这个图形即形成下划线效果。如果要显示出下划线背后的网页背景,可以使用透明的.gif图形。

  其次,如果下划线图形的高度较大,则必须适当增加文本的高度,使得一行文本的底部与下一行文本的顶部之间有较大的空间,例如p { line-height: 1.5; }。

自定义链接下划线举例

  网页源代码如下:
  
注:diagonal.gif 和 flower.gif已经先拷贝到网页所在的同一目录下。

  <html>
  <head>
  <title>ex</title>

  <style type="text/css">

  a#example1a {
    text-decoration: none;
    background: url(diagonal.gif) repeat-x 100% 100%;
    white-space: nowrap;
    padding-bottom: 2px;
    }

  a#example1b {
    text-decoration: none;
    white-space: nowrap;
    padding-bottom: 2px;
    }

  a#example1b:hover {
    background: url(diagonal.gif) repeat-x 100% 100%;
    }

  a#example2a {
    text-decoration: none;
    background: url(flower.gif) repeat-x 100% 100%;
    white-space: nowrap;
    padding-bottom: 10px;
    }

  a#example2b {
    text-decoration: none;
    white-space: nowrap;
    padding-bottom: 10px;
    }

  a#example2b:hover {
    background: url(flower.gif) repeat-x 100% 100%;
    }

  -->
  </style>
  </head>

  <body>

  <p>实例:</p>
  <p> <a href="#" id="example1a">波纹线静态下划线</a>,
  <a href="#" id="example1b">鼠标停留时出现的波纹线</a>。</p>
  <p> <a href="#" id="example2a">花朵静态下划线</a>,
  <a href="#" id="example2b">鼠标停留时出现的花朵下划线</a>。</p>

  </body>
  </html>


上一篇:利用CSS,不通过replace替换标引HTML标记
下一篇:对CSS类及id的规范化命名
作者:  来源: ( 责任编辑:7dspace )
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐