[英]Add underline to text with using text-decoration underline - CSS
Following is my HTML/CSS code in which I am trying to add a underline below the text without using native text-decoration: underline
property. 以下是我的HTML / CSS代码,其中我尝试在文本下方添加下划线,而不使用本机text-decoration: underline
属性。 But somehow this code is not working. 但是以某种方式,此代码无法正常工作。 Any pointers what I am doing wrong here 任何指针我在这里做错了
HTML Code - HTML代码-
<span>
<a class="test">Add Underline To Text</a>
</span>
CSS Code - CSS代码-
.test {
position: relative;
text-decoration: none;
}
.test:hover {
width: 100%:
}
.test:after {
content: '';
position: absolute;
left: 0;
bottom: -7px;
height: 4px;
background-color: green;
width: 0;
transition: width .25s;
}
Codepen Link - https://codepen.io/anon/pen/VEBNyx Codepen链接- https://codepen.io/anon/pen/VEBNyx
You want to add width
to :after
when you hover the .test
link ? 您要在:after
.test
悬停.test
链接:after
增加width
:after
Then you need to write test:hover:after { }
. 然后,您需要编写test:hover:after { }
。 Not just test:hover
. 不仅仅是test:hover
。
Even though :after
is a pseudo-element you must select it if you want to change it's style/s 即使:after
是伪元素,如果要更改其样式,也必须选择它
See below 见下文
.test { position: relative; text-decoration: none; } .test:hover:after { width: 100%; } .test:after { content: ''; position: absolute; left: 0; bottom: -7px; height: 4px; background-color: green; width: 0; transition: width .25s; }
<span> <a class="test">Add Underline To Text</a> </span>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.