首先,这是我的目标
我使用Stack Overflow做到了这一点。
我该怎么做才能在新闻和类型之间划清界限?为什么我虽然使用了标签,但新闻和类型为什么会合而为一<span>
?
.news_title h3{
overflow: hidden;
text-align: center;
}
.news_title h3:before,
h3:after {
background-color: #000;
content: "";
display: inline-block;
height: 1px;
position: relative;
vertical-align: middle;
width: 50%;
}
.news_title h3:before{
right: 0.5em;
margin-left: -50%;
}
.news_title h3:after{
left: 0.5em;
margin-right: -50%;
}
<div class="news_title">
<h3><span>NEWS</span></h3>
<span>Types</span>
这是结果https://jsfiddle.net/yhn5pfkm/
您必须将两个标签都包装到一个div中,才能在两个标签之前和之后添加一行。而且您必须h3
display: inline
避免移动Types
到下一行。
的CSS
.news_title > div{
overflow: hidden;
text-align: center;
}
.news_title > div:before,
.news_title > div:after {
background-color: #000;
content: "";
display: inline-block;
height: 1px;
position: relative;
vertical-align: middle;
width: 50%;
}
.news_title > div:before{
right: 0.5em;
margin-left: -50%;
}
.news_title > div:after{
left: 0.5em;
margin-right: -50%;
}
.news_title > div > h3{
display: inline;
}
html
<div class="news_title">
<div>
<h3><span>NEWS</span></h3>
<span>Types</span>
</div>
</div>
如果您还需要在新闻和类型之间添加界线,请添加以下CSS:
.news_title h3:after{
background-color: #000;
content: "";
display: inline-block;
height: 1px;
position: relative;
vertical-align: middle;
width: 10px;
margin-left: 5px;
box-sizing: border-box;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句