我尝试创建悬停动画按钮,但我不知道为什么当我单击div时它无法正常工作如果我点击他们的文本即使我在锚标签中写display:block
也是如此。
下面是我的html和css代码也是jsfiddle。
Html:
<div class="animation-button">
<div class="raised hoverable">
<div class="anim"></div><span><a href="index.php?option=com_content&view=about&Itemid=104">More About Us</a></span>
</div>
</div>
Css:
.animation-button .raised {
position: relative;
margin: 1em;
font-weight: 100;
padding: 10px 19px;
text-align: center;
//min-width:14%;
/*width: 200px;*/
/*border-radius: 5px;*/
overflow: hidden;
position: relative;
z-index: 0;
cursor: pointer;
display: inline-block;
}
.animation-button .raised {
-moz-transition: all 0.1s;
-o-transition: all 0.1s;
-webkit-transition: all 0.1s;
transition: all 0.1s;
background: #849C8E;
box-shadow: 0px 1px 1px #849C8E;
}
.animation-button .raised:active {
background: #70897A;
box-shadow: 0px 1px 1px #70897A;
/* display: inline-block; */
}
.animation-button .raised span a {
font-weight: 400;
font-size: 3vw;
color: #fff;
text-decoration: none;
display: block;
}
.animation-button span a:hover,#ankur span a:focus{
color: #fff;
display: block;
}
.anim {
-moz-transform: translateY(-50%) translateX(-50%);
-ms-transform: translateY(-50%) translateX(-50%);
-webkit-transform: translateY(-50%) translateX(-50%);
transform: translateY(-50%) translateX(-50%);
position: absolute;
top: 50%;
left: 50%;
z-index: -1;
}
.anim:before {
position: relative;
content: '';
display: block;
margin-top: 100%;
}
.anim:after {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
border-radius: 50%;
}
.hoverable:hover > .anim {
-moz-animation: anim-out 0.75s;
-webkit-animation: anim-out 0.75s;
animation: anim-out 0.75s;
}
.hoverable:hover > .anim:after {
-moz-animation: anim-out-pseudo 0.75s;
-webkit-animation: anim-out-pseudo 0.75s;
animation: anim-out-pseudo 0.75s;
}
@-webkit-keyframes anim-in {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
@-moz-keyframes anim-in {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
@-ms-keyframes anim-in {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
@keyframes anim-in {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
@-webkit-keyframes anim-in-pseudo {
0% {
background: rgba(0, 0, 0, 0.25);
}
100% {
background: transparent;
}
}
@-moz-keyframes anim-in-pseudo {
0% {
background: rgba(0, 0, 0, 0.25);
}
100% {
background: transparent;
}
}
@-ms-keyframes anim-in-pseudo {
0% {
background: rgba(0, 0, 0, 0.25);
}
100% {
background: transparent;
}
}
@keyframes anim-in-pseudo {
0% {
background: rgba(0, 0, 0, 0.25);
}
100% {
background: transparent;
}
}
@-webkit-keyframes anim-out {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
@-moz-keyframes anim-out {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
@-ms-keyframes anim-out {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
@keyframes anim-out {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
@-webkit-keyframes anim-out-pseudo {
0% {
background: rgba(0, 0, 0, 0.25);
}
100% {
background: transparent;
}
}
@-moz-keyframes anim-out-pseudo {
0% {
background: rgba(0, 0, 0, 0.25);
}
100% {
background: transparent;
}
}
@-ms-keyframes anim-out-pseudo {
0% {
background: rgba(0, 0, 0, 0.25);
}
100% {
background: transparent;
}
}
@keyframes anim-out-pseudo {
0% {
background: rgba(0, 0, 0, 0.25);
}
100% {
background: transparent;
}
}
答案 0 :(得分:2)
将填充添加到a
标记而不是button
,以便链接覆盖按钮的整个区域,如下所示:
.animation-button .raised {
position: relative;
margin: 1em;
font-weight: 100;
text-align: center;
//min-width:14%;
/*width: 200px;*/
/*border-radius: 5px;*/
overflow: hidden;
position: relative;
z-index: 0;
cursor: pointer;
display: inline-block;
}
.animation-button .raised {
-moz-transition: all 0.1s;
-o-transition: all 0.1s;
-webkit-transition: all 0.1s;
transition: all 0.1s;
background: #849C8E;
box-shadow: 0px 1px 1px #849C8E;
}
.animation-button .raised:active {
background: #70897A;
box-shadow: 0px 1px 1px #70897A;
/* display: inline-block; */
}
.animation-button .raised span a {
font-weight: 400;
font-size: 3vw;
color: #fff;
text-decoration: none;
display: block;
padding: 10px 19px;
}
.animation-button span a:hover,
#ankur span a:focus {
color: #fff;
display: block;
}
.anim {
-moz-transform: translateY(-50%) translateX(-50%);
-ms-transform: translateY(-50%) translateX(-50%);
-webkit-transform: translateY(-50%) translateX(-50%);
transform: translateY(-50%) translateX(-50%);
position: absolute;
top: 50%;
left: 50%;
z-index: -1;
}
.anim:before {
position: relative;
content: '';
display: block;
margin-top: 100%;
}
.anim:after {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
border-radius: 50%;
}
.hoverable:hover>.anim {
-moz-animation: anim-out 0.75s;
-webkit-animation: anim-out 0.75s;
animation: anim-out 0.75s;
}
.hoverable:hover>.anim:after {
-moz-animation: anim-out-pseudo 0.75s;
-webkit-animation: anim-out-pseudo 0.75s;
animation: anim-out-pseudo 0.75s;
}
@-webkit-keyframes anim-in {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
@-moz-keyframes anim-in {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
@-ms-keyframes anim-in {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
@keyframes anim-in {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
@-webkit-keyframes anim-in-pseudo {
0% {
background: rgba(0, 0, 0, 0.25);
}
100% {
background: transparent;
}
}
@-moz-keyframes anim-in-pseudo {
0% {
background: rgba(0, 0, 0, 0.25);
}
100% {
background: transparent;
}
}
@-ms-keyframes anim-in-pseudo {
0% {
background: rgba(0, 0, 0, 0.25);
}
100% {
background: transparent;
}
}
@keyframes anim-in-pseudo {
0% {
background: rgba(0, 0, 0, 0.25);
}
100% {
background: transparent;
}
}
@-webkit-keyframes anim-out {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
@-moz-keyframes anim-out {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
@-ms-keyframes anim-out {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
@keyframes anim-out {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
@-webkit-keyframes anim-out-pseudo {
0% {
background: rgba(0, 0, 0, 0.25);
}
100% {
background: transparent;
}
}
@-moz-keyframes anim-out-pseudo {
0% {
background: rgba(0, 0, 0, 0.25);
}
100% {
background: transparent;
}
}
@-ms-keyframes anim-out-pseudo {
0% {
background: rgba(0, 0, 0, 0.25);
}
100% {
background: transparent;
}
}
@keyframes anim-out-pseudo {
0% {
background: rgba(0, 0, 0, 0.25);
}
100% {
background: transparent;
}
}
<div class="animation-button">
<div class="raised hoverable">
<div class="anim"></div><span><a href="index.php?option=com_content&view=about&Itemid=104">More About Us</a></span>
</div>
</div>