如何用中间的图片和文字设置 <hr> 的样式?

How to style this <hr> with image and text in the middle?

所以我用中间的图像和文本的想法来设计这条水平线,但卡住了。如何将图像对齐到 "TEXT" 的左侧而不是下方?这是 link 来演示当前状态:

http://codepen.io/anon/pen/MJWJad

感谢所有帮助。

.horizontal__rule--modified {
  line-height: 1em;
  position: relative;
  border: 0;
  color: #666666;
  text-align: center;
  height: 1.5em;
  opacity: 0.7;
  letter-spacing: 1px;
  font-size: 16px;
  &:before {
    content: url(http://www.metalguitarist.org/forum/images/mgtwitter.png);
    background: red;
    position: absolute;
    left: 0;
    top: 50%;
    width: 100%;
    height: 2px;
  }
  &:after {
    content: attr(data-content);
    position: relative;
    display: inline-block;
    color: black;
    padding: 0 .5em;
    line-height: 1.5em;
    color: red;
    background-color: #fcfcfa;
  }
}

<hr class="horizontal__rule--modified" data-content="TEXT">

实际上您在这里根本不需要 <hr />。您可以只使用伪元素并使其成为可能:

* {
  font-family: 'Segoe UI';
  font-weight: normal;
}
h1 {
  text-align: center;
}
h1 span {
  background-color: #fff;
  padding: 15px;
}
h1::after {
  display: block;
  content: "";
  border: 1px solid #ccc;
  margin-top: -0.5em;
}
<h1><span>Hello</span></h1>

如果需要图片,例如 a twitter icon, you can use: Source:

* {
  font-family: 'Segoe UI';
  font-weight: normal;
  vertical-align: middle;
}
h1 {
  text-align: center;
  font-size: 14pt;
}
h1 span {
  background-color: #fff;
  padding: 15px;
}
h1::after {
  display: block;
  content: "";
  border: 1px solid #ccc;
  margin-top: -0.5em;
}
<h1>
  <span>
    <img src="http://www.metalguitarist.org/forum/images/mgtwitter.png" alt="" />
    Hello
  </span>
</h1>

预览

除了 Praveen 之外的另一种解决方案是使用 flex-box。

HTML

<div class="wrapper">
  <div class="line"></div>
  <div class="text">
    Test
  </div>
  <div class="line"></div>
</div>

CSS

.wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.line {
  height: 10px;
  background: black;
  width: 100%;
}
.text {
  padding: 0 10px;
}

fiddle: https://jsfiddle.net/jdgqmmv5/