简体   繁体   English

悬停时显示下划线的文本

[英]Text that shows an underline on hover

Can you underline a text on hover using css?您可以使用 css 在悬停时为文本加下划线吗? (Like the behavior of a link but not an actual link.) (就像链接的行为,但不是实际链接。)

  1. you have the following text Hello work你有以下文字你好工作
  2. when you hover your mouse over the text it underlines it using css当您将鼠标悬停在文本上时,它会使用 css 给它加下划线

(the text is not a link) (文字不是链接)

<span class="txt">Some Text</span>

.txt:hover {
    text-decoration: underline;
}

You just need to specify text-decoration: underline;你只需要指定text-decoration: underline; withpseudo-class :hover .使用伪类:hover

HTML HTML

<span class="underline-on-hover">Hello world</span>

CSS CSS

.underline-on-hover:hover {
    text-decoration: underline;
}

I have whipped up a working Code Pen Demo .我已经创建了一个有效的Code Pen Demo

Fairly simple process I am using SCSS obviously but you don't have to as it's just CSS in the end!相当简单的过程我显然正在使用 SCSS,但您不必这样做,因为它最终只是 CSS!

HTML HTML

<span class="menu">Menu</span>

SCSS社会保障局

.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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM