Pau*_*aul 11
您可以使用:before伪元素并为其添加边框.
h1 {
position: relative;
line-height: 1.2em;
}
h1:before {
position: absolute;
left: 0;
top: 1.2em;
height: 0;
width: 50px;
content: '';
border-top: 1px solid red;
}Run Code Online (Sandbox Code Playgroud)
<h1>This is a header, partly underlined</h1>Run Code Online (Sandbox Code Playgroud)
使用pseudo-element:
h1 {
position: relative;
}
h1::before {
content: '';
position: absolute;
bottom: 0; left: 0;
width: 50px;
height: 2px;
background-color: green;
}Run Code Online (Sandbox Code Playgroud)
<h1>foobar</h1>Run Code Online (Sandbox Code Playgroud)