html - 文本下方居中对齐线

标签 html css

我的 h2 元素下面有一行。

它是左对齐的,但我想将它居中对齐到正下方的文本。

有人可以帮助解决这个问题吗?

演示:https://jsfiddle.net/4es6ugjn/

h2 {
  display:block
}

h2:after {
    border-bottom: 4px solid #ae263d;
    content: "";
    display: block;
    margin-top: 10px;
    width: 50px;
}
<h2 class="text-center">Welcome to our Website</h2>

最佳答案

试试这个

h2 {
    display: inline-block;
    position:relative;
}
h2:after {
    border-bottom: 4px solid #ae263d;
    content: "";
    display: block;
    width: 50px;
    left: 0;
    right: 0;
    margin: 0 auto;
    position:absolute;
}

关于html - 文本下方居中对齐线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41462687/

相关文章:

css - 将 Css 应用于多个类

javascript无法获取类的计算样式

html - 如何将 Html 转换为 Prolog

php - 在 HTML 样式 =""CSS 中使用 PHP 简码

javascript - getElementById 并动态创建 div?

html - 定位具有 float 属性的元素

javascript - jquery fade div颜色改变

javascript - 在空 RSS 提要后显示文本

html - Firefox 上的 Angular 不会调整 div 容器的大小

html - 链接在 Materialise 选项卡中不起作用