Is It Possible in CSS to Transition Through a Third Color When Using a Hover Transition

Is it possible in CSS to transition through a third color when using a hover transition?

you could use keyframes for this:

.element {  background-color: red;  height: 300px;  width: 300px;}.element:hover {    -webkit-animation: changeColor 0.4s forwards;  animation: changeColor 0.4s forwards;}
@-webkit-keyframes changeColor{ 0%{background: red;} 50%{background:yellow} 100%{background:green} }@keyframes changeColor{ 0%{background: red;} 50%{background:yellow} 100%{background:green} }
<div class="element"></div>

CSS3 color transition on hover, but on click have immediate color change

Use transition-property:none;

.menuButton:active {
color: #880000;
-webkit-transition-property: none;
-moz-transition-property: none;
-o-transition-property: none;
-ms-transition-property: none;
transition-property: none;
}

Force transition to complete on hover CSS

a CSS only solution by adding this code:

.popup-button-ctr:hover::before {
content:"";
position:fixed;
top:0;
left:0;
right:0;
bottom:0;
animation:h calc(var(--transition-time) + var(--transition-delay)) forwards;
}
@keyframes h {
99.9% {bottom:0;}
100% {bottom:100%}
}

This will increase the hoverable area to the whole screen to make sure you will keep the hover effect until the end of transition.

@import url('https://fonts.googleapis.com/css2?family=M+PLUS+1p&display=swap');
:root {
--init-bubble-padding: 0px;
--bubble-padding: 10px;
--triangle-height: 12px;
--transition-delay: 0ms;
--transition-time: 400ms;
}

* {
font-family: 'M PLUS 1p', Verdana, Geneva, Tahoma, sans-serif;
z-index: 100;
}

.popup-button-ctr {
display: inline-block;
position: relative;
outline: 0px solid red;
}

.button-ctr button {
background-color: rgba(30, 30, 30, 1);
border: none;
border-radius: 5px;
outline: 0px solid rgb(90, 90, 90);
font-weight: 900;
color: rgb(205, 205, 205);
padding: 8px 10px 8px 10px;
}

.button-ctr button:hover {
color: white;
cursor: pointer;
background-color: rgba(50, 50, 50, 1);
}

.triangle-up,
.triangle-right,
.triangle-down,
.triangle-left {
pointer-events: none;
display: relative;
position: absolute;
text-shadow: 1px 1px 10px rgba(21, 36, 63, 0.4);
z-index: 50;
color: rgba(255, 0, 0, 1);
background-color: transparent;
opacity: 0;
visibility: hidden;
transform: scale(0);
transition: var(--transition-time) ease-in-out;
transition-delay: var(--transition-delay);
transition-property: opacity, visibility, transform, top, right, bottom, left;
}

.popup-posr-up,
.popup-posr-right,
.popup-posr-down,
.popup-posr-left {
width: 0;
height: 0;
z-index: 150;
position: absolute;
}

.popup-posr-down {
left: 50%;
}

.popup-button-ctr .triangle-down {
transform: rotate(0deg) translateX(-50%);
top: var(--init-bubble-padding);
}

.popup-button-ctr:hover .triangle-down {
transform: rotate(0deg) translateX(-50%);
opacity: 1;
visibility: visible;
transition: var(--transition-time) ease-in-out;
transition-delay: var(--transition-delay);
top: var(--bubble-padding);
}

.popup-button-ctr:hover::before {
content:"";
position:fixed;
top:0;
left:0;
right:0;
bottom:0;
animation:h calc(var(--transition-time) + var(--transition-delay)) forwards;
}
@keyframes h {
99.9% {bottom:0;}
100% {bottom:100%}
}
<div class="popup-button-ctr">

<div class="button-ctr">
<button>
<div style="font-size: 30px">
Emoji Button
</div>
This button has emojis <br />
Let's ROCK br> </button>
</div>

<div class="popup-posr-down">
<div class="triangle-down">

</div>
</div>

</div>

Is it possible to prevent a CSS transition reversing off hover?

Yes, it is indeed. The trick is to make the width transition out take 0s with a delay of 1s.

html,
body {
margin: 0;
padding: 0;
}

a.btn--tertiary {
padding-left: 0;
padding-right: 0;
background-color: transparent;
color: #000;
border: 0;
position: relative;
padding-bottom: 5px;
text-transform: uppercase;
text-decoration: none;
font-size: 40px;
}

.btn--tertiary::before {
content: '';
height: 2px;
right: 0;
width: 100%;
background: #000;
position: absolute;
bottom: 0;
transition: width 0s;
z-index: 2;
border-left: 10px solid transparent;
}

.btn--tertiary::after {
content: '';
height: 2px;
left: 0;
right: auto;
width: 0%;
background: grey;
position: absolute;
bottom: 0;
opacity: 0;
transition: opacity .5s, width 0s .5s;
z-index: 3;
}

.btn--tertiary:hover:before,
.btn--tertiary:focus:before {
width: 0%;
border-left: 20px solid $white;
transition: width 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) 0s;
}

.btn--tertiary:hover::after,
.btn--tertiary:focus::after {
right: 0;
width: 100%;
opacity: 1;
transition: opacity 0s, width 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) 0.1s;
}
<a href="#" class="btn--tertiary">Button</a>

Animate Colour Change transitions

Sounds like a job for jQuery - specifically, for the animate() method:

http://api.jquery.com/animate/

Hover off transition css

Your answer

You have added the transition property on the hover state of the element. Therefore the transition is not applied when you leave the cursor from the element.

.shape1{
position: absolute;
background: red;
top: 512px;
width: 180px;
height: 140px;
transition: .2s ease; /* move this here from :hover */
}

Further information

Besides this you can also add specific properties to the transition. For example, if you only want the height to be animated you could it like this:

.shape1 {
transition: height .2s ease;
/* this inly affects height, nothing else */
}

You can even define different transition-times for each property:

.shape1 {
transition: height .2s ease, background-color .5s linear;
/* stacking transitions is easy */
}

CSS :after hover Transition

Firefox 4+ is the only browser that supports the transitioning of pseudo-elements such as :before and :after.

Source: http://css-tricks.com/13555-transitions-and-animations-on-css-generated-content/



Related Topics



Leave a reply



Submit