对字体文字加下划线样式, 有两种方法, 一直直接使用 html 下划线标签, 另外一种是使用 CSS 下划线样式. 下面我们来看一下使用 CSS 添加下划线的方法.
CSS 可以使用 text-decoration 属性添加下划线. 使用 text-decoration:underline; 样式即可为文本添加下划线.
示例:
- <!DOCTYPE HTML>
- <HTML>
- <head>
- <meta charset="utf-8">
- <title>
- </title>
- <style>
- h1 {text-decoration:overline;} h2 {text-decoration:line-through;} h3 {text-decoration:underline;}
- </style>
- </head>
- <body>
- <h1>
- This is heading 1
- </h1>
- <h2>
- This is heading 2
- </h2>
- <h3>
- This is heading 3
- </h3>
- </body>
- </HTML>
效果如下:
text-decoration 属性说明:
text-decoration 属性规定添加到文本的修饰.
注释: 修饰的颜色由 "color" 属性设置.
这个属性允许对文本设置某种效果, 如加下划线. 如果后代元素没有自己的装饰, 祖先元素上设置的装饰会 "延伸" 到后代元素中. 不要求用户代理支持 blink.
属性值:
none 默认. 定义标准的文本.
underline 定义文本下的一条线.
overline 定义文本上的一条线.
line-through 定义穿过文本下的一条线.
blink 定义闪烁的文本.
inherit 规定应该从父元素继承 text-decoration 属性的值.
推荐: CSS 手册 https://www.html.cn/book/css/
来源: http://www.css88.com/qa/css3/13734.html