Hr类双边框

时间:2016-08-30 05:44:44

标签: css class

我正在通过.css hr班级

请求您的帮助

我正试图弄清楚如何制作这样的双边框:

Sample

这就是我所做的:

hr.style15 {
    border-top: 4px double black;
}
hr.style15:after {
    content: 'SHIPPING INFO';
    display: inline-block;
    position: relative;
    top: -15px;
    left: 40px;
    padding: 0 10px;
    background: #f0f0f0;
    color: #8c8b8b;
    font-size: 18px;
}

我的问题是:

1)如何摆脱2行以下的inline-block?我试过删除inline-block句子,但它不起作用。

2)我可以为此添加font-family和字体大小吗?

3)是否可以在不增加宽度的情况下增加2条线之间的间距?

2 个答案:

答案 0 :(得分:1)

基本上我相信我会采用不同的方式。同时使用:after和:之前的行将帮助您大幅度地将文本放在其上。

所以我为你准备了这个CodePen。基本上我所做的是使用:after和a:之前(正如我之前告诉你的那样)的边界线,之后我在边界线的顶部添加了一个背景颜色的跨度(在这种情况下为白色) (看看z-index)。

.container {
  width: 800px;
  position: relative;
}

.double-bar {
  &:after {
    content: "";
    border-bottom: 1px solid black;
    width: 100%;
    position: absolute;
    top: 9px;
    left: 0;
    z-index: 1;
  }

  &:before {
    content: "";
    border-bottom: 1px solid black;
    width: 100%;
    position: absolute;
    top: 13px;
    left: 0;
    z-index: 1;    
  }

  span {
    z-index: 2;
    position: relative;
    background-color: white;
    left: 40px;
    padding: 0 7.5px;
    text-transform: uppercase;
    font-weight: 600;
    font-size: 20px;
  }
}

你可以看到demo这个。

我希望这有帮助!

答案 1 :(得分:0)

请检查一下: -

<强> HTML

<h1 class="title"><span>Shipping info</span></h1>

<强> CSS

    h1.title {
        margin-top: 0;
        position: relative;
    }
    h1.title:before {
        content: "";
        display: block;
        border-top: solid 1px black;
        width: 100%;
        height: 2px;
        position: absolute;
        top: 50%;
        z-index: 1;
        border-bottom: 1px solid #000;
    }

    h1.title span {
       background: #fff;
       padding: 0 20px;
       position: relative;
       z-index: 5;
       margin-left: 50px;
    }
相关问题