如何为文本创建自定义边框

时间:2017-06-22 11:26:18

标签: html css border

如何获得边框如下图所示。

enter image description here

enter image description here

众所周知,我为文本尝试了border-bottom。但是无法像这样了解边界。我会尝试使用伪元素吗?

3 个答案:

答案 0 :(得分:3)

您可以使用:before:after伪元素在元素底部创建两行,并使用position: absolute定位它们。



h1 {
  position: relative;
  display: inline-block;
  margin: 25px;
}
h1:after,
h1:before {
  content: '';
  position: absolute;
  bottom: -2px;
  height: 1px;
  width: 60%;
  left: 0;
  background: #C0932E;
  transform: translateY(100%);
}
h1:after {
  height: 3px;
  width: 30%;
}
.center:before,
.center:after {
  left: 50%;
  transform: translate(-50%, 100%);
}
.start:before {
  width: 100%;
}

<h1 class="start">LOREM IPSUM</h1><br>
<h1 class="center">Lorem ipsum dolor.</h1>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

h1 {
  display:inline-block;
  position:relative;
  padding-bottom:4px;
}
h1:before {
  display:block;
  content:"";
  width:70%;
  height:1px;
  background:orange;
  position:absolute;
  left:50%;
  bottom:0;
  transform:translate(-50%);
}
h1:after {
  display:block;
  content:"";
  width:20%;
  height:4px;
  background:orange;
  position:absolute;
  left:50%;
  bottom:-4px;
  transform:translate(-50%);
}
<h1>
Vijay Kumar
</h1>

答案 2 :(得分:0)

试试这个:

h1 {
    border-bottom: 2px solid orange;
    width: 200px;
    text-align: center;
    position: relative;
}

h1:after{
    content: '';
    position: absolute;
    width: 100px;
    border-bottom: 3px solid orange;
    top: 39px;
    left: 50px;
}
<h1>This is Test</h1>