html - 将文本放在 <hr> 的中间

标签 html css

基本上,我希望在我的文本后面有一个 hr 并且我的文本将位于它的中间。

这是一些示例标记:

<div class="test">
  <hr class="middle-line"/>
  Some Text
</div>

.test {
  text-align: center;
}

hr.middle-line {
    width: 0px;
    height: 100px;
    z-index: -1;
  }

链接到 fiddle ; https://jsfiddle.net/hLh55t7p/

最佳答案

您可以像这样使用绝对定位:

.test {
  text-align: center;
  position: relative
}

hr.middle-line {
    width: 0px;
    height: 100px;
    z-index: -1;
}
.test p{
  position: absolute;
  text-align: center;
  top: 0;
  width: 100%
}
<div class="test">
  <hr class="middle-line"/>
  <p>Some Text</p>
</div>

关于html - 将文本放在 <hr> 的中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34952960/

相关文章:

javascript - 通过变量创建简单页面

html - 使倾斜的div内的图像正常

javascript - &lt;script&gt; require ('renderer.js' ) &lt;/script&gt; - 不连接js文件

html - 使容器 div 成为一个子 div 的高度,并使另一个子 div 成为容器的高度

html - 电子邮件 HTML 正文中的 VBA IF 条件

javascript - js flipcards 中的故障 - 翻转

google-chrome - Chrome/webkit 不呈现输入 :checked + element + element 上的 css 显示更改

html - border-radius 后面的背景颜色

css - SASS 未正确预处理

html - 在 IE8、7、6 上使用列表呈现错误