水平线在文本中间 [英] Horizontal line in the middle of text

查看:127
本文介绍了水平线在文本中间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在中间显示一个带有单词的水平线,如下所示:

I want to display a horizontal line with words in the middle so that it looks like following:

我在尝试这项功能,但不起作用:

I'm trying this and doesn't work:

HTML:

<h2><span>Test</span></h2>

CSS:

h2{
    font-size: 100px;
    border-top: solid 1px black;
    width: 100%;
    height: 50px;
    margin-top: 25px;
    top: 50%;
    z-index: 1;    
}

span{
     background: #fff;
      padding: 0 20px;
      margin-top:-25px;
       display: inline-block;
       z-index: 5;
}

JSFiddle:
http://jsfiddle.net/2ds9a/

推荐答案

可用于 css

像这样

HTML

<h2><span  class="line-center">Test</span></h2>

Css

.line-center{
    margin:0;padding:0 10px;
    background:#fff;
    display:inline-block;
}
h2{

    text-align:center;
    position:relative;
    z-index:2;

}
h2:after{
    content:"";
    position:absolute;
    top:50%;
    left:0;
    right:0;
    border-top:solid 1px red;
    z-index:-1;
}

LIve演示

LIve Demo

这篇关于水平线在文本中间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆