你能使用CSS在鼠标悬停时给文本添加下划线吗?(类似于链接的行为,但不是实际链接。)
- 你有以下文本 Hello work
- 当你将鼠标悬停在文本上时,使用CSS给它添加下划线
(该文本不是链接)
<span class="txt">Some Text</span>
.txt:hover {
text-decoration: underline;
}
您只需在伪类:hover
中指定text-decoration: underline;
即可。
<span class="underline-on-hover">Hello world</span>
.underline-on-hover:hover {
text-decoration: underline;
}
我已经制作了一个可运行的Code Pen Demo。
text-decoration-color
CSS 属性结合使用,以覆盖默认的蓝色外观,并将颜色与您要下划线的文本匹配。 - AuthorOfTheSurf我正在使用相当简单的过程,显然我正在使用SCSS,但你也不必如此,因为最终它只是CSS!
<span class="menu">Menu</span>
.menu {
position: relative;
text-decoration: none;
font-weight: 400;
color: blue;
transition: all .35s ease;
&::before {
content: "";
position: absolute;
width: 100%;
height: 2px;
bottom: 0;
left: 0;
background-color: yellow;
visibility: hidden;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
&:hover {
color: yellow;
&::before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
}
}
li {
display:inline-block;
padding:15px;
}
li:hover {
color: Blue;
border-bottom: 3px solid Blue;
}
<ul>
<li>Hello work</li>
</ul>
.resume_link:hover{
text-decoration: underline;
text-decoration-color: rgb(250, 114, 64);
-moz-text-decoration-color: rgb(250, 114, 64);
text-decoration-thickness: 5px;
}
<a class="resume_link">Resume</a>
<span class="text">Click Me</span>
.text:hover {
text-decoration: underline black //This colour is an example
}