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

html-css012

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

一般有两种方法:

一、通过CSS下划线代码:text-decoration:underline来设置文字下划线。

实例演示如下:

1、实例代码如下:

此时页面效果如下:

2、修改第1步中的txt样式,加入text-decoration:underline。

此时页面效果如下,出现了下划线。

二、通过设置div的border实现效果:

实例演示如下:

在第一种方法的初始代码上,增加border-bottom: 1px solid black、padding-bottom: 10px两个关键样式,如下:

此时页面效果如下:

要在文字中间实现有一条横线的效果可以使用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。

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Title</title>

<style>

body{background: #f0f0f0}

.con{position:relativeheight:1.875remline-height: 1.875remmargin:2.47rem autotext-align: center}

.con i{display:blockheight:1pxbackground:#e1e1e1position:absolutetop:0.9remwidth:100%}

.con p{

display:inline-block

font-size: 0.75rem

color:#c1c1c1

background:rgba(240,240,240,1)

padding:0 1.875rem

text-align: center

margin:0 auto

position:relative

z-index:2}

</style>

</head>

<body>

<div class="con">

<i></i>

<p>到底了</p>

</div>

</body>

</html>

这里使用了背景色和透明度,细心的人可能会发现,body设置的背景色刚好是‘到底了’的文字的背景色,同时也用了行内块、透明度以及相对定位来实现了的噢。