Font Awesome 不适用于 CSS 旋转
Font Awesome doesn't work with CSS rotation
我试图在鼠标悬停时旋转图标。它似乎对我不起作用。过渡效果效果很好。我想知道我是否使用了错误的标签来应用旋转。这是代码:
@import 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css';
@import 'https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css';
.list-icon-wrapper {
text-align: center;
}
.aticon i {
border-radius: 50%;
background: #5e8cfa;
width: 160px;
height: 160px;
text-align: center;
line-height: 100px;
vertical-align: middle;
padding: 30px;
color: #fff;
font-size: 60px;
}
.icon-wrapper:hover i {
background: #fff;
color: #5e8cfa;
border: 1px solid #5e8cfa;
transition: all 0.6s ease 0s;
-webkit-transition: all 0.6s ease 0s;
-moz-transition: all 0.6s ease 0s;
-ms-transition: all 0.6s ease 0s;
-o-transition: all 0.6s ease 0s;
display: inline-block;
}
.aticon:hover .fa {
transform: rotate(360deg);
-webkit-transform: rotate(360deg);
-o-transform: rotate(360deg);
-ms-transform: rotate(360deg);
-moz-transform: rotate(360deg);
}
.list-icon-wrapper .icon-wrapper p {
padding: 0 5px;
font-weight: 500;
font-size: 18px;
margin-top: 15px;
color: #000;
text-align: center;
display: inline-block;
}
<div class="list-icon-wrapper">
<div class="col-md-4">
<div class="icon-wrapper">
<span class="aticon">
<i class="fa fa-magnet"></i>
</span>
<p>Magnet</p>
</div>
</div>
<div class="col-md-4">
<div class="icon-wrapper">
<span class="aticon">
<i class="fa fa-clock-o"></i>
</span>
<p>Clock</p>
</div>
</div>
</div>
FontAwesome 实际上在 :before
伪元素上呈现图标而不是作为背景图像。我认为您需要做的就是瞄准那个而不是 .fa
元素。这应该可以帮助您入门。
.icon-wrapper:hover .fa::before {
background: #fff;
color: #5e8cfa;
border: 1px solid #5e8cfa;
transition: all 0.6s ease 0s;
-webkit-transition: all 0.6s ease 0s;
-moz-transition: all 0.6s ease 0s;
-ms-transition: all 0.6s ease 0s;
-o-transition: all 0.6s ease 0s;
display: inline-block;
}
.aticon:hover .fa::before {
transform-origin: center;
-ms-transform-origin: center;
-webkit-transform-origin: center;
transform: rotate(360deg);
-webkit-transform: rotate(360deg);
-o-transform: rotate(360deg);
-ms-transform: rotate(360deg);
-moz-transform: rotate(360deg);
}
我试图在鼠标悬停时旋转图标。它似乎对我不起作用。过渡效果效果很好。我想知道我是否使用了错误的标签来应用旋转。这是代码:
@import 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css';
@import 'https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css';
.list-icon-wrapper {
text-align: center;
}
.aticon i {
border-radius: 50%;
background: #5e8cfa;
width: 160px;
height: 160px;
text-align: center;
line-height: 100px;
vertical-align: middle;
padding: 30px;
color: #fff;
font-size: 60px;
}
.icon-wrapper:hover i {
background: #fff;
color: #5e8cfa;
border: 1px solid #5e8cfa;
transition: all 0.6s ease 0s;
-webkit-transition: all 0.6s ease 0s;
-moz-transition: all 0.6s ease 0s;
-ms-transition: all 0.6s ease 0s;
-o-transition: all 0.6s ease 0s;
display: inline-block;
}
.aticon:hover .fa {
transform: rotate(360deg);
-webkit-transform: rotate(360deg);
-o-transform: rotate(360deg);
-ms-transform: rotate(360deg);
-moz-transform: rotate(360deg);
}
.list-icon-wrapper .icon-wrapper p {
padding: 0 5px;
font-weight: 500;
font-size: 18px;
margin-top: 15px;
color: #000;
text-align: center;
display: inline-block;
}
<div class="list-icon-wrapper">
<div class="col-md-4">
<div class="icon-wrapper">
<span class="aticon">
<i class="fa fa-magnet"></i>
</span>
<p>Magnet</p>
</div>
</div>
<div class="col-md-4">
<div class="icon-wrapper">
<span class="aticon">
<i class="fa fa-clock-o"></i>
</span>
<p>Clock</p>
</div>
</div>
</div>
FontAwesome 实际上在 :before
伪元素上呈现图标而不是作为背景图像。我认为您需要做的就是瞄准那个而不是 .fa
元素。这应该可以帮助您入门。
.icon-wrapper:hover .fa::before {
background: #fff;
color: #5e8cfa;
border: 1px solid #5e8cfa;
transition: all 0.6s ease 0s;
-webkit-transition: all 0.6s ease 0s;
-moz-transition: all 0.6s ease 0s;
-ms-transition: all 0.6s ease 0s;
-o-transition: all 0.6s ease 0s;
display: inline-block;
}
.aticon:hover .fa::before {
transform-origin: center;
-ms-transform-origin: center;
-webkit-transform-origin: center;
transform: rotate(360deg);
-webkit-transform: rotate(360deg);
-o-transform: rotate(360deg);
-ms-transform: rotate(360deg);
-moz-transform: rotate(360deg);
}