[英]CSS Transition hover effect for touch devices
I'm trying to get a hover/ touch effect when I tap a button using CSS. 当我使用CSS点击按钮时,我试图获得悬停/触摸效果。 I have used the below CSS transition to change the background, but it doesn't seem to work: 我已经使用下面的CSS转换来更改背景,但是它似乎不起作用:
https://jsfiddle.net/s3vbgos7/ https://jsfiddle.net/s3vbgos7/
HTML 的HTML
<div role="button" class="ico-btn red"></div>
CSS 的CSS
.ico-btn {
-webkit-user-select: none; margin-right: 0px;
-webkit-box-shadow: rgba(0, 0, 0, 0.298039) 0px 2px 10px 0px, rgba(0, 0, 0, 0.0980392) 0px 0px 1px 0px, rgba(255, 255, 255, 0.247059) 0px 1px 0px 0px inset, rgba(0, 0, 0, 0.14902) 0px -1px 0px 0px inset;
-webkit-font-smoothing: antialiased;
border-bottom-left-radius: 25%;
border-bottom-right-radius: 25%;
border-top-left-radius: 25%;
border-top-right-radius: 25%;
box-shadow: rgba(0, 0, 0, 0.298039) 0px 2px 10px 0px, rgba(0, 0, 0, 0.0980392) 0px 0px 1px 0px, rgba(255, 255, 255, 0.247059) 0px 1px 0px 0px inset, rgba(0, 0, 0, 0.14902) 0px -1px 0px 0px inset;
cursor: pointer;
display: block;
font-family: Roboto, Arial, sans-serif;
font-size: 140px;
font-weight: normal;
height: 177px; /*167px;*/
line-height: 150px;
min-width: 0px;
padding: 40px 0 0 0; /*30*/
text-align: center;
white-space: nowrap;
width: 220px;/*200*/
z-index: 2;
margin: 0 auto;
color:#fff;
}
.ico-btn.red { background-color: rgb(219, 68, 55);
background-image: -moz-linear-gradient( 90deg, rgb(170,34,23) 0%, rgb(170,34,23) 0%, rgb(195,51,39) 22%, rgb(219,68,55) 100%);
background-image: -webkit-linear-gradient( 90deg, rgb(170,34,23) 0%, rgb(170,34,23) 0%, rgb(195,51,39) 22%, rgb(219,68,55) 100%);
background-image: -ms-linear-gradient( 90deg, rgb(170,34,23) 0%, rgb(170,34,23) 0%, rgb(195,51,39) 22%, rgb(219,68,55) 100%);
border-bottom-color:#ab2318;
border-bottom-left-radius: 25%;
border-bottom-right-radius: 25%;
border-bottom-style: solid;
border-bottom-width: 1px;
border-left-color: rgb(0, 0, 0);
border-left-style: none;
border-left-width: 0px;
border-right-color: rgb(0, 0, 0);
border-right-style: none;
border-right-width: 0px;
border-top-color:#ef675c;
border-top-left-radius: 25%;
border-top-right-radius: 25%;
border-top-style: solid;
border-top-width: 2px;
transition: all .1s linear;
}
.ico-btn.red:hover {
background-color: #D05944;
-webkit-transition: background-color .25s ease-in-out;
-moz-transition: background-color .25s ease-in-out;
-o-transition: background-color .25s ease-in-out;
transition: background-color .25s ease-in-out;
}
Your background-image: -moz-linear-gradient( 90deg, rgb(170,34,23) 0%, rgb(170,34,23) 0%, rgb(195,51,39) 22%, rgb(219,68,55) 100%);
您的background-image: -moz-linear-gradient( 90deg, rgb(170,34,23) 0%, rgb(170,34,23) 0%, rgb(195,51,39) 22%, rgb(219,68,55) 100%);
is overriding the background-color
in the :hover
state. 在:hover
状态下覆盖background-color
。
If you loose the background-image, it will work: 如果您松开背景图片,它将起作用:
.ico-btn { -webkit-user-select: none; margin-right: 0px; -webkit-box-shadow: rgba(0, 0, 0, 0.298039) 0px 2px 10px 0px, rgba(0, 0, 0, 0.0980392) 0px 0px 1px 0px, rgba(255, 255, 255, 0.247059) 0px 1px 0px 0px inset, rgba(0, 0, 0, 0.14902) 0px -1px 0px 0px inset; -webkit-font-smoothing: antialiased; border-bottom-left-radius: 25%; border-bottom-right-radius: 25%; border-top-left-radius: 25%; border-top-right-radius: 25%; box-shadow: rgba(0, 0, 0, 0.298039) 0px 2px 10px 0px, rgba(0, 0, 0, 0.0980392) 0px 0px 1px 0px, rgba(255, 255, 255, 0.247059) 0px 1px 0px 0px inset, rgba(0, 0, 0, 0.14902) 0px -1px 0px 0px inset; cursor: pointer; display: block; font-family: Roboto, Arial, sans-serif; font-size: 140px; font-weight: normal; height: 177px; /*167px;*/ line-height: 150px; min-width: 0px; padding: 40px 0 0 0; /*30*/ text-align: center; white-space: nowrap; width: 220px;/*200*/ z-index: 2; margin: 0 auto; color:#fff; } .ico-btn.red { background-color: rgb(219, 68, 55); border-bottom-color:#ab2318; border-bottom-left-radius: 25%; border-bottom-right-radius: 25%; border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; border-top-color:#ef675c; border-top-left-radius: 25%; border-top-right-radius: 25%; border-top-style: solid; border-top-width: 2px; transition: all .1s linear; } .ico-btn.red:hover { background-color: #D05944; -webkit-transition: background-color .25s ease-in-out; -moz-transition: background-color .25s ease-in-out; -o-transition: background-color .25s ease-in-out; transition: background-color .25s ease-in-out; }
<div role="button" class="ico-btn red"><span class="icon-sad"></span> </div>
In ico-btn.red
remove following lines as they override hover state: 在ico-btn.red
删除以下行,因为它们覆盖了悬停状态:
background-color: rgb(219, 68, 55);
background-image: -moz-linear-gradient( 90deg, rgb(170,34,23) 0%, rgb(170,34,23) 0%, rgb(195,51,39) 22%, rgb(219,68,55) 100%);
background-image: -webkit-linear-gradient( 90deg, rgb(170,34,23) 0%, rgb(170,34,23) 0%, rgb(195,51,39) 22%, rgb(219,68,55) 100%);
background-image: -ms-linear-gradient( 90deg, rgb(170,34,23) 0%, rgb(170,34,23) 0%, rgb(195,51,39) 22%, rgb(219,68,55) 100%);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.