BiPredicate
.arrow {
display: inline-block;
height: 8px;
width: 8px;
margin-top: 20px;
border-top: solid black 2.5px;
border-left: solid black 2.5px;
-ms-transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transition: transform 1s;
-moz-transition: transform 1s;
transition: transform 1s;
cursor: pointer;
}
.arrow::before {
content: "";
display: inline-block;
width: 18px;
margin-left: -3px;
margin-bottom: 7px;
border-top: solid black 1.8px;
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
}
.arrow:hover {
-ms-transform: scale(1.2);
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
transform: scale(1.2);
}
我使用css绘制一个箭头,并尝试使用css:hover和transform:scale创建一个悬停放大效果。但是,代码首先旋转箭头,然后再将其放大。我想知道为什么旋转发生,我该如何解决?提前致谢!
答案 0 :(得分:3)
将此CSS用于悬停:
.arrow:hover {
-ms-transform: scale(1.2) rotate(-45deg);
-webkit-transform: scale(1.2) rotate(-45deg);
-moz-transform: scale(1.2) rotate(-45deg);
transform: scale(1.2) rotate(-45deg);
}
旋转已在整个元素上设置,并且在悬停变换期间未计算。
here是一个有效的例子
答案 1 :(得分:3)
.arrow {
display: inline-block;
height: 8px;
width: 8px;
margin-top: 20px;
border-top: solid black 2.5px;
border-left: solid black 2.5px;
-ms-transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transition: transform 1s;
-moz-transition: transform 1s;
transition: transform 1s;
cursor: pointer;
}
.arrow::before {
content: "";
display: inline-block;
width: 18px;
margin-left: -3px;
margin-bottom: 7px;
border-top: solid black 1.8px;
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
}
.arrow:hover {
-ms-transform: rotate(-45deg) scale(1.2);
-webkit-transform: rotate(-45deg) scale(1.2);
-moz-transform: rotate(-45deg) scale(1.2);
transform: rotate(-45deg) scale(1.2);
}
<span class="arrow"></span>
问题是转换属性不总结,如果覆盖属性并希望保留它的原始值,则需要重复它。
答案 2 :(得分:0)
您只能将转换提供给:before
,以便在悬停时不会旋转。
.arrow {
display: inline-block;
height: 1px;
width: 18px;
border-top: solid black 1.8px;
-webkit-transition: transform 1s;
-moz-transition: transform 1s;
transition: transform 1s;
cursor: pointer;
}
.arrow:before {
content: "";
display: inline-block;
margin-top: -10px;
height: 8px;
width: 8px;
border-top: solid black 2.5px;
border-left: solid black 2.5px;
-ms-transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transition: transform 1s;
-moz-transition: transform 1s;
transition: transform 1s;
cursor: pointer;
position: relative;
top: -9px;
}
.arrow:hover {
-ms-transform: scale(1.2);
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
transform: scale(1.2);
}
<span class="arrow"></span>