简体   繁体   English

用户将鼠标悬停在文本上方时如何删除文本

[英]how to strike out text when a user hovers over it

When a user hovers over a button I want to strike out the text. 当用户将鼠标悬停在按钮上时,我想删除文本。

Here is what I have so far: 这是我到目前为止的内容:

 button{ background-color: Transparent; background-repeat:no-repeat; border: none; cursor:pointer; overflow: hidden; outline:none; color: white; } body{ background-color: black } 
 <button>Hello</button> 

Any suggestion please 有什么建议吗

Just use the :hover CSS pseudo-class and the text-decoration CSS property . 只需使用:hover CSS伪类text-decoration CSS属性即可

And, really, if you just want text and aren't really making a clickable button , you can use just about any element, but a div allows you to remove all the styling you had to make the button not look like a button. 而且,实际上,如果您只想要文本而不是真正创建可单击的button ,则可以使用几乎任何元素,但是div允许您删除使按钮看起来不像按钮的所有样式。

 body { background-color: black } div { color: white; cursor:pointer; } div:hover { text-decoration:line-through; } 
 <div>Hello</div> 

Here is the code: 这是代码:

 .btn-stroke{ background-color: Transparent; background-repeat:no-repeat; border: none; cursor:pointer; overflow: hidden; outline:none; color: white; position: relative; line-height: 1; } /* Create a stroke with 0% of width */ .btn-stroke:after{ display: block; content: ''; position: absolute; top: 50%; transform: translateY(-50%); width: 0%; height: 5px; background-color: #000; transition: width 0.5s; } /* Using hover :pseudo-class increase width */ .btn-stroke:hover:after { width: 100%; } body{ background-color: black } 
 <button class="btn-stroke">Hello</button> 

Here is you code updated. 这是您的代码更新。

<button>Hello</button>




button {
      background-color: Transparent;
      background-repeat: no-repeat;
      border: none;
      cursor: pointer;
      overflow: hidden;
      outline: none;
      color: white;
    }

    body {
      background-color: black
    }

    button:hover {
      text-decoration: line-through;
}

You have to add only hover on your button, and text-decoration: line-through; 您只需在按钮上添加鼠标悬停,然后进行文本装饰:

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

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