如何在hr标签中间留出空间?

时间:2016-01-24 08:11:15

标签: html css html5 css3

JSFIDDLE: https://jsfiddle.net/vezz82tr/

HTML代码:

<div>
Section 1...
</div>
<hr>
<div>
Section 2...
</div>

CSS代码:

hr {
  border: 0;
  border-top: 4px double white;
  text-align: center;
}
hr:after {
  content: '\2665';
  display: inline-block;
  position: relative;
  top: -12px;
  padding: 0 10px;
  background: transparent;
  color: white;
  font-size: 18px;
}

如您所见,小时中间有一个图标。我想在hr的中间给出一些空格,所以这些线条不会高于或低于图标。有什么建议吗?

1 个答案:

答案 0 :(得分:1)

您可以使用 Flexbox

执行此操作

&#13;
&#13;
.line {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
}

hr {
  border: 0;
  border-top: 4px double black;
  flex: 1;
  z-index: 1;
}

i:after {
  font-size: 30px;
  color: black;
  padding: 20px;
  content: '\2665';
  display: inline-block;
}
&#13;
<div class="line">
  <hr>
    <i class="heart"></i>
  <hr>
</div>
&#13;
&#13;
&#13;