h1自定义边框底部宽度而不是全宽

时间:2017-05-02 09:08:30

标签: css css3

这就是我需要的:

enter image description here

这就是我所拥有的:

h1 {
    border-bottom: 3px solid red;
}

并且边框是全角...

有一个很好的解决方案吗?

2 个答案:

答案 0 :(得分:4)

尝试使用display:inline-block

display: inline-block;

Example

答案 1 :(得分:0)

以下是您的回答fiddle link

<div class="full-width">
<h1>Lorem</h1><br/>
<h1>Loerm ipsum h1</h1><br/>
<h1>Other Loerm ipsum h1</h1>
</div>

h1{
   border-bottom: 3px solid red;
   display: inline-block;
    text-align:center;

}
.full-width{
  text-align:center
}