关于在段落前后添加水平线的问题

时间:2015-12-15 07:53:25

标签: css css3

请告诉我如何升级以下代码以使结果看起来像

enter image description here



p::before {
   content: "";
    display: block;
    height: 1px;
    width: 20%;
    margin: 10px;
    background: #f00;
}
p::after {
   content: "";
    display: block;
    height: 1px;
    width: 20%;
    margin: 10px;
    background: #f00;
}

<div class="col-md-12"><p>paragraph text</p></div>
&#13;
&#13;
&#13;

现在我得到了这个

enter image description here

1 个答案:

答案 0 :(得分:1)

display更改为inline-block,我还将保证金更改为em值,以便根据字体大小进行缩放

p::before {
   content: "";
    display: inline-block;
    height: 1px;
    width: 20%;
    margin: 0.3em;
    background: #f00;
}
p::after {
   content: "";
    display: inline-block;
    height: 1px;
    width: 20%;
    margin: 0.3em;
    background: #f00;
}
<div class="col-md-12"><p>paragraph text</p></div>