如何在 CSS 悬停时添加不同的 CSS3 悬停过渡
How to add different CSS3 hover transitions on hover out with CSS
我的问题具体涉及尝试不同的 CSS 悬停时的背景过渡,而不是悬停时的过渡,使用 CSS。
此问题引用了 CSS3 悬停效果,可在 Ian Lunn GitHub CSS3 Hover effects
See codepen here,或查看下面的代码。
代码:
<style>
.hvr-shutter-in-horizontal {
display: inline-block;
vertical-align: middle;
background: rgba(121,61,61, 0.7);
-webkit-transform: translateZ(0);
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
position: relative;
-webkit-transition-property: color;
transition-property: color;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
}
.hvr-shutter-in-horizontal:before {
content: "";
position: absolute;
z-index: -1;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(77,79,79, 0.7);
-webkit-transform: scaleX(1);
transform: scaleX(1);
-webkit-transform-origin: 50%;
transform-origin: 50%;
-webkit-transition-property: transform;
transition-property: transform;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
}
.hvr-shutter-in-horizontal:hover, .hvr-shutter-in-horizontal:focus, .hvr-shutter-in-horizontal:active {
color: white;
}
.hvr-shutter-in-horizontal:hover:before, .hvr-shutter-in-horizontal:focus:before, .hvr-shutter-in-horizontal:active:before {
-webkit-transform: scaleX(0);
transform: scaleX(0);
}
</style>
<a href="#" class="hvr-shutter-in-horizontal">View our Training Workshops</a>
我想更改此按钮的鼠标移开,使其与以下 CSS 产生的鼠标移开相同:
/* Sweep To Bottom */
.hvr-sweep-to-bottom {
display: inline-block;
vertical-align: middle;
-webkit-transform: translateZ(0);
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
position: relative;
-webkit-transition-property: color;
transition-property: color;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
}
.hvr-sweep-to-bottom:before {
content: "";
position: absolute;
z-index: -1;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: #2098d1;
-webkit-transform: scaleY(0);
transform: scaleY(0);
-webkit-transform-origin: 50% 0;
transform-origin: 50% 0;
-webkit-transition-property: transform;
transition-property: transform;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
}
.hvr-sweep-to-bottom:hover, .hvr-sweep-to-bottom:focus, .hvr-sweep-to-bottom:active {
color: white;
}
.hvr-sweep-to-bottom:hover:before, .hvr-sweep-to-bottom:focus:before, .hvr-sweep-to-bottom:active:before {
-webkit-transform: scaleY(1);
transform: scaleY(1);
}
这是概念示例,它为鼠标悬停时的高度和鼠标移开时的颜色设置动画
根据评论更新了伪元素
div {
position: relative;
height: 30px;
background: red;
transition: background 1s;
}
div:after {
content: '';
position: absolute;
left: 50%;
top: 0;
right: 0;
height: 100%;
background: red;
transition: background 1s;
}
div:hover {
height: 120px;
background: blue;
transition: height 1s;
}
div:hover:after {
top: 100%;
background: yellow;
transition: top 1s;
}
<div></div>
我的问题具体涉及尝试不同的 CSS 悬停时的背景过渡,而不是悬停时的过渡,使用 CSS。
此问题引用了 CSS3 悬停效果,可在 Ian Lunn GitHub CSS3 Hover effects
See codepen here,或查看下面的代码。 代码:
<style>
.hvr-shutter-in-horizontal {
display: inline-block;
vertical-align: middle;
background: rgba(121,61,61, 0.7);
-webkit-transform: translateZ(0);
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
position: relative;
-webkit-transition-property: color;
transition-property: color;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
}
.hvr-shutter-in-horizontal:before {
content: "";
position: absolute;
z-index: -1;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(77,79,79, 0.7);
-webkit-transform: scaleX(1);
transform: scaleX(1);
-webkit-transform-origin: 50%;
transform-origin: 50%;
-webkit-transition-property: transform;
transition-property: transform;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
}
.hvr-shutter-in-horizontal:hover, .hvr-shutter-in-horizontal:focus, .hvr-shutter-in-horizontal:active {
color: white;
}
.hvr-shutter-in-horizontal:hover:before, .hvr-shutter-in-horizontal:focus:before, .hvr-shutter-in-horizontal:active:before {
-webkit-transform: scaleX(0);
transform: scaleX(0);
}
</style>
<a href="#" class="hvr-shutter-in-horizontal">View our Training Workshops</a>
我想更改此按钮的鼠标移开,使其与以下 CSS 产生的鼠标移开相同:
/* Sweep To Bottom */
.hvr-sweep-to-bottom {
display: inline-block;
vertical-align: middle;
-webkit-transform: translateZ(0);
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
position: relative;
-webkit-transition-property: color;
transition-property: color;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
}
.hvr-sweep-to-bottom:before {
content: "";
position: absolute;
z-index: -1;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: #2098d1;
-webkit-transform: scaleY(0);
transform: scaleY(0);
-webkit-transform-origin: 50% 0;
transform-origin: 50% 0;
-webkit-transition-property: transform;
transition-property: transform;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
}
.hvr-sweep-to-bottom:hover, .hvr-sweep-to-bottom:focus, .hvr-sweep-to-bottom:active {
color: white;
}
.hvr-sweep-to-bottom:hover:before, .hvr-sweep-to-bottom:focus:before, .hvr-sweep-to-bottom:active:before {
-webkit-transform: scaleY(1);
transform: scaleY(1);
}
这是概念示例,它为鼠标悬停时的高度和鼠标移开时的颜色设置动画
根据评论更新了伪元素
div {
position: relative;
height: 30px;
background: red;
transition: background 1s;
}
div:after {
content: '';
position: absolute;
left: 50%;
top: 0;
right: 0;
height: 100%;
background: red;
transition: background 1s;
}
div:hover {
height: 120px;
background: blue;
transition: height 1s;
}
div:hover:after {
top: 100%;
background: yellow;
transition: top 1s;
}
<div></div>