自定多姿多彩的网页链接下划线

news/2024/7/8 5:31:44 标签: 图形, css, url, html
htmledit_views"> CSS本身没有直接提供变换HTML链接下划线的功能,但只要运用一些技巧,我们还是可以让单调的网页链接下划线变得丰富多彩。

 

  一、基本原理

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

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

src="http://www.yesky.com/imagesnew/software//0407/26/html" title=css>css/ex.htm" frameborder="0" width="560" scrolling="no" height="120">自定义链接下划线示例

  第三,为显示出自定义的下划线,必须隐藏默认的下划线,即a { text-decoration: none; }。

  第四,为链接元素设置下划线html" title=图形>图形,构造出自定义的下划线。假设下划线html" title=图形>图形是underline.gif,则设置下划线html" title=图形>图形的CSS代码为a { background-image: html" title=url>url(underline.gif); }。

  第五,我们要让下划线html" title=图形>图形在水平方向反复出现,但不能在垂直方向重复出现,否则它将被隐藏到文本的背后。要求下划线只在水平方向重复出现的代码为:a { background-repeat: repeat-x; }。

  第六,为保证html" title=图形>图形出现在链接文字的下方(不管字体的大小),用background-position属性将html" title=图形>图形放在链接元素的底部。对于箭头之类的下划线html" title=图形>图形,可能还要考虑html" title=图形>图形在水平方向的对齐方向。假设要将下划线html" title=图形>图形放在右下角,CSS代码为:a { background-position: 100% 100%; }。

  第七,为了在链接文本的下方给自定义html" title=图形>图形留出空间,必须加入适当的空白。下划线html" title=图形>图形相对于链接文字的具体位置与文字的大小有关,但一般而言,可以先让底部空白等于下划线html" title=图形>图形的高度,必要时再作调整。例如:a { padding-bottom: 4px; }。

  第八,由于下划线html" title=图形>图形放在链接元素的底部,必须保证链接不折行(如允许链接跨越多个行,则只有下面一行的链接文本下面会有自定义的下划线)。用CSS的white-space属性可以防止链接文字折行,即a { white-space: nowrap; }。

  综上所述,为链接元素定义CSS样式属性的完整例子如:

  a {
   text-decoration: none;
   background: html" title=url>url(underline.gif) repeat-x 100% 100%;
   padding-bottom: 4px;
   white-space: nowrap;
  }

 

  如果要让自定义下划线只在鼠标停留时出现,只要把原来直接设置在链接元素上的CSS background属性改到:hover ,例如:

  a {
   text-decoration: none;
   padding-bottom: 4px;
   white-space: nowrap;
  }

  a:hover {
   background: html" title=url>url(underline.gif) repeat-x 100% 100%;
  }

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

 

  一、基本原理

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

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

src="http://www.yesky.com/imagesnew/software//0407/26/html" title=css>css/ex.htm" frameborder="0" width="560" scrolling="no" height="120">自定义链接下划线示例

  第三,为显示出自定义的下划线,必须隐藏默认的下划线,即a { text-decoration: none; }。

  第四,为链接元素设置下划线html" title=图形>图形,构造出自定义的下划线。假设下划线html" title=图形>图形是underline.gif,则设置下划线html" title=图形>图形的CSS代码为a { background-image: html" title=url>url(underline.gif); }。

  第五,我们要让下划线html" title=图形>图形在水平方向反复出现,但不能在垂直方向重复出现,否则它将被隐藏到文本的背后。要求下划线只在水平方向重复出现的代码为:a { background-repeat: repeat-x; }。

  第六,为保证html" title=图形>图形出现在链接文字的下方(不管字体的大小),用background-position属性将html" title=图形>图形放在链接元素的底部。对于箭头之类的下划线html" title=图形>图形,可能还要考虑html" title=图形>图形在水平方向的对齐方向。假设要将下划线html" title=图形>图形放在右下角,CSS代码为:a { background-position: 100% 100%; }。

  第七,为了在链接文本的下方给自定义html" title=图形>图形留出空间,必须加入适当的空白。下划线html" title=图形>图形相对于链接文字的具体位置与文字的大小有关,但一般而言,可以先让底部空白等于下划线html" title=图形>图形的高度,必要时再作调整。例如:a { padding-bottom: 4px; }。

  第八,由于下划线html" title=图形>图形放在链接元素的底部,必须保证链接不折行(如允许链接跨越多个行,则只有下面一行的链接文本下面会有自定义的下划线)。用CSS的white-space属性可以防止链接文字折行,即a { white-space: nowrap; }。

  综上所述,为链接元素定义CSS样式属性的完整例子如:

  a {
   text-decoration: none;
   background: html" title=url>url(underline.gif) repeat-x 100% 100%;
   padding-bottom: 4px;
   white-space: nowrap;
  }

 

  如果要让自定义下划线只在鼠标停留时出现,只要把原来直接设置在链接元素上的CSS background属性改到:hover ,例如:

  a {
   text-decoration: none;
   padding-bottom: 4px;
   white-space: nowrap;
  }

  a:hover {
   background: html" title=url>url(underline.gif) repeat-x 100% 100%;
  }

 

http://www.niftyadmin.cn/n/1405852.html

相关文章

c# webservice上传下载

WebService代码: /// ///上传文件 /// ///文件的byte[] ///上传文件的路径 ///上传文件名字 /// [WebMethod] public boolUploadFile(byte[] fs, string path, string fileName) { bool flag false; try …

常用CSS样式

按钮样式*/.ButtonCss {}{ font-family: "Tahoma", "宋体"; font-size:9pt; color: #003399; border: 1px #003399 solid; color:006699; BORDER-BOTTOM: #93bee2 1px solid; BORDER-LEFT: #93bee2 1px solid; BORDER-RIGHT: #93be…

oracle top newid()

SELECT * FROM "dizhi" where ROWNUM<1001 ORDER BY SYS_GUID()

自定义聚集函数,仿wm_concat,使用CLOB,可处理超过4000长度字符串

因开发需要&#xff0c;在使用wm_concat函数时&#xff0c;在字符串长度超过4000后报错&#xff0c;所以自定义一个类似的聚集函数&#xff0c;在内部使用CLOB处理&#xff0c;避免超长问题。 源码如下&#xff1a; 先以sys用户授权&#xff1a; grant execute on dbms_lob to …

JNI入门

学习了一下JNI&#xff0c;发表文章的时候不知道该选什么好了&#xff0c;不知道JNI应该属于那个范畴^_^。1&#xff0e; 简介JNI是Java Native Interface的缩写&#xff0c;它的设计目的是&#xff1a; The standard Java class library may not support the platform…

下载文件和将文件转换为数据流下载的示例C#

下载文件和将文件转换为数据流下载的示例C# protected void Page_Load(object sender, EventArgs e) { string file Request["file"]; if (string.IsNullOrEmpty(file)) return; string filepath Server.MapPath("~/…

使用模板模式简化DAO操作Hibernate

相信使用过Spring &#xff0b; Hibernate开发过的人&#xff0c;在写DAO的时候都使用过Spring的HibernateDaoSupport类&#xff0c;然后在实现的时候就可以很轻松的使用getHibernateTemplate()方法之后就可以调用save()、delete()、update()等Hibernate的Session的操作&#x…

流下载

代码如下: string fileName strName;//客户端保存的文件名 string filePath "http://.....//a.zip";//路径 //以字符流的形式下载文件 FileStream fs new FileStream(filePath, FileMode.OpenOrCreate,FileAccess.Write); byte[…