CSS 字体真棒动画微调通过背景
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34210417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
font awesome animated spinner through background
提问by SatAj
I am using font awesome spin icon through CSS background for loading the page.
我正在通过 CSS 背景使用字体真棒旋转图标来加载页面。
/* Styles go here */
.loading-icon {
position: relative;
width: 20px;
height: 20px;
margin:50px auto;
}
.loading-icon:before {
content: "\f110";
font-family: FontAwesome;
font-size:20px;
position: absolute;
top: 0;
}
<!DOCTYPE html>
<html>
<head>
<link data-require="fontawesome@*" data-semver="4.5.0" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.css" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="loading-icon"></div>
</body>
</html>
The icon is rendering successfully in the page, but it is a static. How can I use the animated spinning icon using font awesome as a background? Kindly assist.
图标在页面中渲染成功,但它是静态的。如何使用字体真棒作为背景使用动画旋转图标?请协助。
采纳答案by SatAj
Correct answer: Update CSS as given below.
正确答案:更新 CSS,如下所示。
/* Styles go here */
.loading-icon {
position: relative;
width: 20px;
height: 20px;
margin:50px auto;
-webkit-animation: fa-spin 2s infinite linear;
animation: fa-spin 2s infinite linear;
}
.loading-icon:before {
content: "\f110";
font-family: FontAwesome;
font-size:20px;
position: absolute;
top: 0;
}
<!DOCTYPE html>
<html>
<head>
<link data-require="fontawesome@*" data-semver="4.5.0" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.css" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="loading-icon"></div>
</body>
</html>
回答by Berendschot
You should use fa fa-spinner fa-spin
.
你应该使用fa fa-spinner fa-spin
.
请参阅:字体真棒示例
Example:
例子:
/** CSS **/
@import url('https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.css');
<!-- HTML -->
<div class="fa fa-spinner fa-spin"></div>
回答by Lucas Bustamante
Font Awesome 4.7
字体真棒 4.7
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<i class="fa fa-spinner fa-spin fa-3x fa-fw"></i>
<i class="fa fa-circle-o-notch fa-spin fa-3x fa-fw"></i>
<i class="fa fa-refresh fa-spin fa-3x fa-fw"></i>
<i class="fa fa-cog fa-spin fa-3x fa-fw"></i>
<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
Font Awesome 5+
字体真棒 5+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">
<div class="fa-3x">
<i class="fas fa-spinner fa-spin"></i>
<i class="fas fa-circle-notch fa-spin"></i>
<i class="fas fa-sync fa-spin"></i>
<i class="fas fa-cog fa-spin"></i>
<i class="fas fa-spinner fa-pulse"></i>
<i class="fas fa-stroopwafel fa-spin"></i>
</div>
Font Awesome 5 Spinner documentation:
Font Awesome 5 Spinner 文档:
https://fontawesome.com/how-to-use/on-the-web/styling/animating-icons
https://fontawesome.com/how-to-use/on-the-web/styling/animating-icons
Font Awesome 5 Spinner Icon list:
Font Awesome 5 Spinner 图标列表: