Put transition only on the normal state:
.design-box {
transition: all 1s ease;
}
Have a look at the snippet below:
.design-box {
width: 100%;
height: 250px;
margin: 100px auto;
border: 1px solid rgba(0, 0, 0, 0.1);
border-radius: 50%;
position: relative;
transition: all 1s ease;
}
.design-box:hover {
border-radius: 0;
}
<div class="design-box"></div>
Answer from Saurav Rastogi on Stack OverflowHow to smoothly transition from a hover to a non hover ?
html - CSS: Smooth transition between hover and leaving - Stack Overflow
css - What is the opposite of :hover (on mouse leave)? - Stack Overflow
html - CSS Transition - eases in but doesn't ease out? - Stack Overflow
Videos
I have a following section of css:
.navbar {
position: fixed;
display: flex;
z-index: 3;
width: 70px;
background-color: black;
height: 100%;
transition: 0.5s;
}
.navbar:hover {
width: 200px;
}
@media (width < 1080px) {
.navbar {
position: sticky;
transition: none;
flex-direction: row;
width: 100%;
height: 100px;
}
.navbar:hover {
width: 100%; }
}It describes a navigation bar that is a sidebar when the viewport is bigger than 1080px. When I hover over it, it stretches to 200px. If the vieport becomes smaller than 1080px, the sidebar becomes horizontal navigation bar.
What I wanted to achieve was a smooth transition of stretching the sidebar on hover and on hover leave. At this moment this works as intended.
What I also wanted was snappy transition from sidebar to horizontal navigation bar and vice versa. Unfortunately it works only partialy. Although I have achieved the snappy transition from sidebar to horizontal navigation bar, I cannot figure out how can I create snappy transition from horizontal navigation bar to sidebar.
I understand what is the problem here (when changing from horizontal navigation bar to sidebar the transtion is set again to 0.5s hence the animation) but I am struggling to figure out how to achieve two-way snappines from sidebar to navbar while maintaining the "hover-in-and-out" transition.
What would be the correct way of achieving such effect ?
Here is example of current state of the sidebar/navbar in jsfiddle: https://jsfiddle.net/mz29afyh/2/
hey everyone , when i used for example
ul:hover{
background-color: green;
transition: all 1.2s ;}
it hovers smoothly , but when i remove my mouse from it it goes back in an instant wich looks a bit ugly , is there a way to make a "reverse" transition ? i tried what i found on google but nothing did work , thanks guys !
So the transition takes place on the hover but not on the off. So you need to set the transition on the element without the hover state.
for example: for your demo add
li.searchbar a.searchbar-text {
transition:all .5s ease;
}
The transition on hover will not affect the normal state
li.searchbar a.searchbar-text{
transition: opacity .9s, margin-left .5s, margin-right .5s;
-webkit-transition: opacity .9s, margin-left .5s, margin-right .5s;
}
li.searchbar a.searchbar-text:hover {
color: red !important;
margin-left:-10px;
}
<li class="col-sm-5 searchbar"><a class="text-left"><i class="fa fa-search" aria-hidden="true"></i></a><a class="searchbar-text"><span class="first-seach-text">Search France</span><span class="second-seach-text">and beyond</span></a></li>
If I understand correctly you could do the same thing by moving your transitions to the link rather than the hover state:
ul li a {
color:#999;
transition: color 0.5s linear; /* vendorless fallback */
-o-transition: color 0.5s linear; /* opera */
-ms-transition: color 0.5s linear; /* IE 10 */
-moz-transition: color 0.5s linear; /* Firefox */
-webkit-transition: color 0.5s linear; /*safari and chrome */
}
ul li a:hover {
color:black;
cursor: pointer;
}
http://jsfiddle.net/spacebeers/sELKu/3/
The definition of hover is:
The :hover selector is used to select elements when you mouse over them.
By that definition the opposite of hover is any point at which the mouse is not over it. Someone far smarter than me has done this article, setting different transitions on both states - http://css-tricks.com/different-transitions-for-hover-on-hover-off/
#thing {
padding: 10px;
border-radius: 5px;
/* HOVER OFF */
-webkit-transition: padding 2s;
}
#thing:hover {
padding: 20px;
border-radius: 15px;
/* HOVER ON */
-webkit-transition: border-radius 2s;
}
The opposite is using :not
e.g.
selection:not(:hover) { rules }
Add the transition properties to the element itself rather than the :hover pseudo-class version.
In doing so, the transition will take place when hovering on and off.
Updated Example
.img-blur {
transition: all 0.35s ease-in-out;
}
.img-blur:hover {
-moz-filter: blur(4px);
-webkit-filter: blur(4px);
filter: blur(4px);
}
<img src="http://i.imgur.com/Vp5StNs.png" class="img-blur" />
If you want different transition properties when hovering on/off, see this example.
The transition property on the element itself will take place when hovering off of the element.
The transition on the
:hoverpseudo class will take place when hovering on the element:
.img-blur {
transition: all 0.35s ease-in-out; /* Hover off */
}
.img-blur:hover {
-moz-filter: blur(4px);
-webkit-filter: blur(4px);
filter: blur(4px);
transition: all 1s ease-in; /* On hover */
}
<img src="http://i.imgur.com/Vp5StNs.png" class="img-blur">
If you want text to be added on hover, take a look at either of these past answers.
https://stackoverflow.com/a/18322705/2680216
https://stackoverflow.com/a/21371665/2680216
Gotta remember you need to tell the computer what happens when it is not getting hovered over. Why you need to add a transition property into the class when its not getting hovered.
here is the CSS:
.nav__menuIcon--button {
visibility: hidden;
width: 24px;
height: 24px;
background-color: transparent;
border-color: transparent;
border-width: 0;
transition: all 300ms ease-in;
}
.nav__menuIcon--button:hover {
color: red;
transition: all 300ms ease-in;
}
The following CSS floats a column but does not reverse the transition, it just jumps back:
selector:hover {
transition: all .3s ease-in-out;
transform: translate(0%, -1.5%);
cursor: pointer;
z-index: 1;
}
Can anyone help me ease out the transition? I have no experience whatsoever