简体   繁体   English

CSS Hover 下划线 Animation

[英]CSS Hover Underline Animation

I'm trying to create a line animation when I hover over a piece of text.当我在一段文本上使用 hover 时,我正在尝试创建一行 animation。 Here's the code I have right now, but it's not working.这是我现在拥有的代码,但它不起作用。

[data-predefined-style="true"] small {
    display: inline-block;
    font-size: 1.8rem;
    line-height: 1.2;
    font-family: "Diatype Variable", Icons;
    font-style: normal;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.85);
    font-variation-settings: 'slnt' 0, 'MONO' 0;
}

[data-predefined-style="true"] small a {
    color: rgba(0, 0, 0, 0.85);
    border-bottom-width: 0em;
}

[data-predefined-style="true"] small a:hover {
    color: rgba(0, 46, 207, 0.8);
    border-bottom-width: 0em;
}

.hover-underline-animation {
  display: inline-block;
  position: relative;
  color: #0087ca;
}

.hover-underline-animation:after {
  content: '';
  position: absolute;
  width: 100%;
  transform: scaleX(0);
  height: 2px;
  bottom: 0;
  left: 0;
  background-color: #0087ca;
  transform-origin: bottom right;
  transition: transform 0.25s ease-out;
}

.hover-underline-animation:hover:after {
  transform: scaleX(1);
  transform-origin: bottom left;
}

I have the code for the hover animation, but I'm not exactly sure how to implement it.我有 hover animation 的代码,但我不确定如何实现它。 Help is greatly appreciated, thank you so much!非常感谢您的帮助,非常感谢!

Seems to be working.似乎正在工作。 What kind of effect are you after?你追求什么样的效果?

 [data-predefined-style="true"] small { display: inline-block; font-size: 1.8rem; line-height: 1.2; font-family: "Diatype Variable", Icons; font-style: normal; font-weight: 500; color: rgba(0, 0, 0, 0.85); } [data-predefined-style="true"] small a { color: rgba(0, 0, 0, 0.85); border-bottom-width: 0em; } [data-predefined-style="true"] small a:hover { color: rgba(0, 46, 207, 0.8); border-bottom-width: 0em; }.hover-underline-animation { display: inline-block; position: relative; color: #0087ca; }.hover-underline-animation:after { content: ''; position: absolute; width: 100%; transform: scaleX(0); height: 2px; bottom: 0; left: 0; background-color: #0087ca; transform-origin: bottom right; transition: transform 0.25s ease-out; }.hover-underline-animation:hover:after { transform: scaleX(1); transform-origin: bottom left; }
 <div class="hover-underline-animation">Hello world</div>

hope this can help you希望这可以帮到你

 [data-predefined-style="true"] small { display: inline-block; font-size: 1.8rem; line-height: 1.2; font-family: "Diatype Variable", Icons; font-style: normal; font-weight: 500; color: rgba(0, 0, 0, 0.85); font-variation-settings: 'slnt' 0, 'MONO' 0; } [data-predefined-style="true"] small a { color: rgba(0, 0, 0, 0.85); border-bottom-width: 0em; } [data-predefined-style="true"] small a:hover { color: rgba(0, 46, 207, 0.8); border-bottom-width: 0em; }.hover-underline-animation { display: inline-block; position: relative; color: #0087ca; }.hover-underline-animation:after { content: ''; position: absolute; width: 100%; transform: scaleX(0); height: 2px; bottom: 0; left: 0; background-color: #0087ca; transform-origin: bottom right; transition: transform 0.25s ease-out; }.hover-underline-animation:hover:after { transform: scaleX(1); transform-origin: bottom left; }
 <h2 class="hover-underline-animation">text with underline animation</h2>

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

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