怎么在文字两边加横线css

html-css010

怎么在文字两边加横线css,第1张

<!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设置的背景色刚好是‘到底了’的文字的背景色,同时也用了行内块、透明度以及相对定位来实现了的噢。

一般有两种方法:

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

实例演示如下:

1、实例代码如下:

此时页面效果如下:

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

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

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

实例演示如下:

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

此时页面效果如下:

<html>

<head>

<title>无标题文档</title>

<style type="text/css">

.box{ border-top:1px solid #F00width:100px}

</style>

</head>

<body>

<div class="box">这是一个测试</div>

</body>

</html>

测试一下是不是你所需要的