我正在工作的客户非常喜欢这些按钮。 https://www.greenwichlibrary.org/
我一直在从检查器中提取他们的代码以开始使用。我快到了,但是我的动画朝相反的方向发展,我对CSS动画的了解还不够,无法找出问题所在。到目前为止,我在这里:https://codepen.io/anon/pen/mYXbJG
我想通过反转动画的方向来使它与灵感匹配的任何帮助。之后,我可以重新编写代码以适合我现有的类,并将SVG替换为图标字体。 :)
<a href="#" class="button explore">Discover Here<span class="button-arrow"><img src="https://www.greenwichlibrary.org/wp-content/themes/greenwich-sage/assets/images/icons/button-arrow.svg"></span></a>
.explore {
background-color: blue;
}
.button {
border: none;
display: inline-block;
height: 16px;
padding: 13px 62px 13px 18px;
position: relative;
text-decoration: none;
-webkit-transform: translateX(0);
-o-transform: translateX(0);
transform: translateX(0);
-webkit-transition: all .3s ease-in-out !important;
-o-transition: all .3s ease-in-out !important;
transition: all .3s ease-in-out !important;
font-size: 14px;
color: #FFF;
}
.button.explore::before {
background-color: green;
}
.button::before {
content: "";
position: absolute;
z-index: -1;
top: 0;
left: 0;
right: 0;
bottom: 0;
height: 42px;
-webkit-transform: scaleX(0);
-o-transform: scaleX(0);
transform: scaleX(0);
-webkit-transform-origin: 0 50%;
-o-transform-origin: 0 50%;
transform-origin: 0 50%;
-o-transition: -o-transform .3s ease-in-out;
transition: transform .3s ease-in-out;
-webkit-transition: -webkit-transform .3s ease-in-out;
}
::after, ::before {
box-sizing: border-box;
}
.button .button-arrow {
display: inline-block;
height: 42px;
overflow: hidden;
position: absolute;
right: 0;
top: 0;
width: 42px;
z-index: 1;
}
.button .button-arrow img {
left: 50%;
position: absolute;
top: 50%;
-webkit-transform: translate(-50%,-50%);
-o-transform: translate(-50%,-50%);
transform: translate(-50%,-50%);
}
.button.explore::after {
background-color: green;
}
.button::after {
content: '';
height: 42px;
padding: 14px 0 15px 16px;
position: absolute;
right: 0;
top: 0;
-webkit-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
width: 42px;
transform-origin:left;
transition:width 0.25s ease;
z-index:-1;
}
.button:hover::after {
width: 100%;
}
.button:active, .button:focus, .button:hover {
color: #FFF;
outline: 0;
text-decoration: none;
}
:active, :focus, :hover, :visited {
outline: 0 !important;
}