首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CSS呼吸<button>停止文本抖动

CSS呼吸<button>停止文本抖动
EN

Stack Overflow用户
提问于 2019-01-08 18:03:50
回答 1查看 1.8K关注 0票数 6

我有一个圆呼吸的click me按钮下面,这里我使用@keyframes动画按钮呼吸-到目前为止,一切都好!

但是正如你所知道的,在呼吸动画中,click me文本在颤抖。

有什么办法可以避免这种情况发生吗?

代码语言:javascript
复制
.centered {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) 
}

button.circle {
  --startSize: 65vh;
  --endSize: 85vh;
  width: var(--startSize);
  height: var(--startSize);
  background: teal;
  border-radius: 100%;
  animation-name: breathe;
  animation-play-state: running;
  animation-duration: 4.5s;
  animation-iteration-count: infinite;
  animation-direction: alternate;
    border: none;

}

@keyframes breathe {
  
  0% {
    width: var(--startSize); 
    height: var(--startSize);
  }
  
  25% {
    width: var(--startSize); 
    height: var(--startSize);
  }

  75% {
    width: var(--endSize);
    height: var(--endSize);
  }
  
  100% {
    width: var(--endSize);
    height: var(--endSize);
  }
}
代码语言:javascript
复制
<a href="https://www.w3schools.com"><button class="circle centered">Click me</button></a>

EN

回答 1

Stack Overflow用户

发布于 2019-01-08 18:25:22

问题是要使用transform属性来对按钮进行居中。我使用网格属性将一个JSFiddle放在一起,将按钮水平和垂直地放在中心,这样就可以阻止文本的抖动。

代码语言:javascript
复制
body,
html {
  height: 100%;
  display: grid;
}

.circle-outer {
  margin: auto;
  text-align: center;
}

button.circle {
  --startSize: 65vh;
  --endSize: 85vh;
  width: var(--startSize);
  height: var(--startSize);
  background: teal;
  border-radius: 100%;
  animation-name: breathe;
  animation-play-state: running;
  animation-duration: 4.5s;
  animation-iteration-count: infinite;
  animation-direction: alternate;
  border: none;
}

@keyframes breathe {
  0% {
    width: var(--startSize);
    height: var(--startSize);
  }
  25% {
    width: var(--startSize);
    height: var(--startSize);
  }
  75% {
    width: var(--endSize);
    height: var(--endSize);
  }
  100% {
    width: var(--endSize);
    height: var(--endSize);
  }
}
代码语言:javascript
复制
<div class="circle-outer">
  <a href="https://www.w3schools.com"><button class="circle">Click me</button></a>
</div>

还有一个工作例子:

https://jsfiddle.net/WebDevelopWolf/7ujm2L5v/11/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54097307

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档