如何使用CSS在文本下面绘制边框?

时间:2017-11-12 05:14:39

标签: html css

我正在使用Bootstrap。我已将文本放在中间,但无法在文本下方的中间形成这个边框。

How to draw border which is thick in the middle as shown in this image using CSS

2 个答案:

答案 0 :(得分:2)

试试这个:

span {
    border-bottom: 1px solid #CCC;
    padding-bottom: 5px;
    position: relative;
}

span:before {
    content: '';
    position: absolute;
    width: 30px;
    border-bottom: 2px solid gray;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
}
<span>National Programming</span> 

答案 1 :(得分:0)

您可以使用linear-gradient()。不需要伪元素:)

div {
  display: inline-block;
  color: #ccc;
  font-size: 40px;
  padding: 5px 0;
  background:linear-gradient(to right, transparent 5%, 
    #ccc 5%, #ccc 40%, 
    #111 40%, #111 55%, 
    #ccc 55%, #ccc 95%, 
    transparent 95% ) bottom;
  background-repeat: no-repeat;
  background-size: 100% 2px;
}
<div>National Programming</div>

NB:在OP的插图中,底部边框并未完全到达文本的边缘 - 因此我在线性渐变的两侧添加了透明色