html - 如何使用CSS消除按钮上的动画闪烁?

标签 html css

我创建了具有悬停效果的按钮。按钮从下到上填充背景颜色为白色,文本颜色发生变化。但是,当动画发生时,底部会出现这条奇怪的线。任何帮助将不胜感激。

.project-button div {
    position: relative;
    display: inline-block;
    padding: 1rem;
    margin: 0 1rem 1rem 1rem;
    
    font-size: 1rem;
    font-weight: 700;
    border: 1px solid white;
    border-radius: 15px;
    
    background-repeat: no-repeat;
    transition: background-size .5s, color .5s;
}

.to-top {
    background-position: 50% 100%;
    background-size: 100% 0%;
}

.project-button a {
    color: white;
}

.project-button div:hover {
    background-size: 100% 100%;
    background-image: linear-gradient(white, white);
}

.color-blue:hover {
    color: #51d0de;
}

/* Misc */
html {
  background: black;
  margin: 1em;
}
<div class="project-button">
    <a href="###"><div class="to-top color-blue">Visit Site</div></a>
</div>

最佳答案

尝试以下操作:

我认为问题与 Chrome 计算动画的方式有关。有时(取决于框架)白色背景太小而无法填充显示黑色背景的按钮(因此闪烁)。

.project-button div {
  position: relative;
  display: inline-block;
  padding: 1rem;
  margin: 0 1rem 1rem 1rem;

  font-size: 1rem;
  font-weight: 700;
  border: 1px solid white;
  border-radius: 15px;

  background-image: linear-gradient(white, white);
  background-repeat: no-repeat;
  background-position: 0 -100%;
  background-size: 100% 200%;
  transition: background-position .5s, color .5s;
}

.project-button a {
  color: white;
}

.project-button div:hover {
  background-position: 0% 0%;
}

.color-blue:hover {
  color: #51d0de;
}

/* Misc */
html {
  background: black;
  margin: 1em;
}
<html lang="en">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body>
    <div class="project-button">
      <a href="###"><div class="color-blue">Visit Site</div></a>
    </div>
  </body>
</html>

灵感来自 Transition background-color via slide up animation

关于html - 如何使用CSS消除按钮上的动画闪烁?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57963831/

相关文章:

html - Django:第 49 行无效的 block 标记: 'endfor',应为 'elif'、 'else' 或 'endif'。您是否忘记注册或加载此标签?

javascript - 如何在域的所有页面上运行javascript脚本?

javascript - CSS float 被反转

Css 矩阵与变换。哪个更快?

html - 将带有伪前/后选择器样式的汉堡包导航居中

javascript - 为什么在div中选择不同的值时滚动条不会改变?

javascript - HTML 计数器从 15 分钟开始一直持续到按下按钮为止?

html - CSS 显示问题

css - Yeoman 教程缺少样式

android - OnsenUI : Google Maps has 0 height when inside <ons-page> (Android 2. 3/仅限 Webkit)