简体   繁体   English

如何使用 CSS3 为字体粗细设置动画?

[英]How to animate font-weight with CSS3?

I want to use only HTML5 and CSS3 only as much as possible on my website.我想在我的网站上尽可能只使用 HTML5 和 CSS3。

I'm trying to animate the text on my contact button.我正在尝试为我的联系按钮上的文本设置动画。 More specifically, I want it to change color and be font-weight: bolder 4 seconds every 20 seconds.更具体地说,我希望它改变颜色并成为font-weight: bolder每 20 秒font-weight: bolder 4 秒。

Right now it does switch colors, but it just won't get bold in Chrome, Safari and Opera.现在它确实可以切换颜色,但它在 Chrome、Safari 和 Opera 中不会变得大胆。 It works fine in Firefox and IE.它在 Firefox 和 IE 中运行良好。

Here is the CSS I'm using:这是我正在使用的 CSS:

#contact {
position: fixed;
margin-top: 63px;
margin-left: 680px;
width: 250px;
height: 55px;
transform:rotate(-36.87deg);
z-index: 20 !important;
font-size: 24px;
line-height: 55px;
text-align: center;
text-decoration: none;
color: #FFFFFF;
transition: all 1s ease;
animation-name: alarmlight;
animation-iteration-count: infinite;
animation-duration: 20s;
}

@keyframes alarmlight {
0% { color: #FFFFFF; font-weight: normal; }
80% { color: #FFFFFF; font-weight: normal; }
85%{ color: #00F; font-weight: bolder; }
90% { color: #F00; font-weight: bolder; }
95% { color: #00F; font-weight: bolder; }
100% { color: #F00; font-weight: bolder; }
}

a#contact:hover {
color: #FFF101 !important;
font-weight:bold !important;
animation-name:none;
transition: all 1s ease;
transform: translate(18px,-18px) rotate(-36.87deg);
}

Check Here to see it in action.在这里查看它的实际效果。

Update: also created a simple jsfiddle to show the problem in its core.更新:还创建了一个简单的jsfiddle来显示其核心问题。

Update: Updated the CSS in this post to reflect the code im using in its current state.更新:更新了这篇文章中的 CSS 以反映我在当前状态下使用的代码。

I actually think browsers just may not support font-weight in animations even though it is listed as a supported property .我实际上认为浏览器可能不支持动画中的字体粗细,即使它被列为受支持的属性 While I was toying with it, I did update your jsfiddle with a bunch of new code to clean things up, like...当我在玩弄它时,我确实用一堆新代码更新了你的jsfiddle来清理东西,比如......

0% { color: #FFFFFF; font-size:1em; }

...combining your animations (no reason to have two), added prefix-free (to avoid all those prefixes), and out of experiment, used font-size instead of font-weight (at least that works). ...结合你的动画(没有理由有两个),添加无前缀(以避免所有这些前缀),并且在实验之外,使用字体大小而不是字体粗细(至少有效)。

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

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