我必须对此进行模拟,但我有两种方法可以做到:
但我不相信这两者中的任何一个.第一个因为它需要一个额外的图像,第二个因为它意味着添加一个额外的元素,这在语义上是不正确的.
有没有添加元素或图像的方法?
我喜欢伪元素,这正是我在这里使用的.
h1{
position:relative;
}
h1:after{
content:"";
position:absolute;
width:20%;
border-top:1px solid green;
bottom:0;
left:40%;
}
Run Code Online (Sandbox Code Playgroud)
如果您希望下划线是固定宽度,则需要使用负边距来居中.
h1:after{
content:"";
position:absolute;
width:100px;
border-top:1px solid green;
bottom:0;
left:50%;
margin-left:-50px;
}
Run Code Online (Sandbox Code Playgroud)