Smi*_*thy 0 html css pseudo-element
因此,我正在设计这个水平线,中间的图像和文字的想法,并卡住了.我如何在"TEXT"左侧对齐图像而不在其下方?这是演示当前状态的链接:
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">
Run Code Online (Sandbox Code Playgroud)
其实你根本不需要一个<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;
}Run Code Online (Sandbox Code Playgroud)
<h1><span>Hello</span></h1>Run Code Online (Sandbox Code Playgroud)
* {
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;
}Run Code Online (Sandbox Code Playgroud)
<h1>
<span>
<img src="http://www.metalguitarist.org/forum/images/mgtwitter.png" alt="" />
Hello
</span>
</h1>Run Code Online (Sandbox Code Playgroud)
预习