怎样用CSS样式在文字下面加下划线

html-css012

怎样用CSS样式在文字下面加下划线,第1张

给需要添加下划线的元素应用如下css样式即可

text-decoration: underline

示例如下:

给需要添加下划线的元素一个标记,这里设置为一个名叫underline的类

<h2>我不加下划线</h2>

<h2 class="underline">我要加下划线</h2>

应用上面给出的添加下划线的样式

h2{color:blue} /*设置文字颜色为蓝色*/

h2.underline{text-decoration: underline} /*只为有underline标识的元素添加下划线*/

效果如下

要在文字中间实现有一条横线的效果可以使用CSS中CSS text-decoration 属性就可以达到效果。

CSS text-decoration 属性相关介绍及事例:

浏览器支持:所有主流浏览器都支持 text-decoration 属性。

定义、用法和说明:text-decoration 属性规定添加到文本的修饰。

CSS text-decoration 属性的值:

A、none    默认。定义标准的文本。

B、underline    定义文本下的一条线。

C、overline    定义文本上的一条线。

D、line-through    定义穿过文本下的一条线。

E、blink    定义闪烁的文本。

F、inherit    规定应该从父元素继承 text-decoration 属性的值。

实例:

h1 {text-decoration:overline}

h2 {text-decoration:line-through}

h3 {text-decoration:underline}

h4 {text-decoration:blink}

设置 h1、h2、h3、h4 元素的文本修饰。

注释:

A、任何的版本的 Internet Explorer (包括 IE8)都不支持属性值 "inherit"。

B、IE、Chrome 或 Safari 不支持 "blink" 属性值。

C、修饰的颜色由 "color" 属性设置。

D、这个属性允许对文本设置某种效果,如加下划线。如果后代元素没有自己的装饰,祖先元素上设置的装饰会“延伸”到后代元素中。不要求用户代理支持 blink。