How to make reverse transition after :hover - html

From my understanding of CSS3 transitions you have to specify the transition only in the base element and not in the :hover element, e.g. as described in the Mozilla documentation. This should lead to a transition when the new properties from :hover are applied and reverse the transition as soon as you don't hover anymore. (Fiddle below code)
#test{
position:absolute;
height: 100px;
width: 100px;
background-color: #A8A8A8;
-o-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-webkit-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#test:hover{
border-bottom: 10px solid black;
}
But this leads to fading-in only. When you stop hovering the border is instantly removed.
http://jsfiddle.net/hcsamkjf/1/
Any ideas?

You also need to specify the "initial state", otherwise the browser doesn't know what to animate. It can sometimes guess, which would be why you see it half-working (but it doesn't transition at all for me).
Add border-bottom:10px solid transparent or border-bottom:0 solid transparent to your #test styles, depending on the exact effect you want.

The issue is that as you are not specifying a border-style in the initial state, when you "unhover", the animation changes from solid to the default value : none. Border-style isn't animatable so the change is sudden.
You need to specify the same border-style in the initial state (note: specify a 0 border-width too to remove default border width) so the animation only affects border-width and stays smooth in both directions.
DEMO
CSS :
#test{
position:absolute;
height: 100px;
width: 100px;
background-color: #A8A8A8;
border-style: solid;
border-width:0px;
-o-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-webkit-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#test:hover{
border-bottom: 10px solid black;
}

Related

Div background-color transition not working

I have added transition to my buttons and it works fine
I have a div with width/height defined inline via props (react), the transition code looks very similar to the button so I'm unsure why it isn't wokring. For this example I just want a simple transition from a white background to red when you hover.
I have set the background color to white initially and :hover to red:
background-color: red;
transition: background-color 0.5s;
-webkit-transition: background-color 0.5s;
-o-transition: background-color 0.5s;
-moz-transition: background-color 0.5s;
However this results in the expected result.. without any transition
I have tried changing the width on hover and setting tranisition: all 1s but it works without any transition again.. Why is this happening?
Thanks
Thanks for the fast responses. My apologies for the missing details. Turns out it was because the AOS (animation on scroll) library causes issues if doing transitions on the same element. I solved this by wrapping the div in another div.
It would help if you showed more of what you have on the hover, but I'm assuming that maybe you have the code set something like this:
.box{
background-color: red;
}
.box:hover{
transition: background-color 0.5s;
-webkit-transition: background-color 0.5s;
-o-transition: background-color 0.5s;
-moz-transition: background-color 0.5s;
}
It should be like this:
.box{
transition: background-color 0.5s;
-webkit-transition: background-color 0.5s;
-o-transition: background-color 0.5s;
-moz-transition: background-color 0.5s;
}
.box:hover{
background-color: red;
}
Usually, the transition is given to the element.
Try this instead -
Css
div {
background-color: white;
transition: background-color 0.5s ease-in-out;
}
div:hover {
background-color: red;
}
Sass -
div {
background-color: white;
transition: background-color 0.5s ease-in-out;
&:hover {
background-color: red;
}
}
Try this, if set initially white to div background. Default it is white.
so, we can add transition , then hover the background change to red
CSS
.box{
transition: background-color 0.5s;
}
.box:hover{
background-color: red;
}
SCSS
.box{
transition: background-color 0.5s;
&:hover{
background-color: red;
}
}
Try this snippet.
.box{
transition: background-color 0.5s;
}
.box:hover{
background-color: red;
}
<div class="box" style="width:100vh;height:100vh;"></div>

CSS animation is not working

Why css animation is not working in my code. When i want to hover my link.
.floridabt-nav .dropdown-menu>li>a:focus, .dropdown-menu>li>a:hover{
background-color: transparent;
color: #f9dd04;
transition: all 0.3s ease;
}
.floridabt-nav .dropdown-menu>li>a:focus:before, .dropdown-menu>li>a:hover:before{
content: "\2192";
color: #222222;
padding-right: 10px;
-moz-transition: padding-right .3s ease-in;
-o-transition: padding-right .3s ease-in;
-webkit-transition: padding-right .3s ease-in;
transition: padding-right .3s ease-in;
}
Look at the snippet. Now the transition works.
ul was missing in the selector
first css rule need of any declaration of padding
you have to put the transition declaration into the first rule (not under hover or focus)
in the second css rule you have to use padding and not padding-right
in the second css rule you don't need of transition declaration
I hope I was of any help.
.floridabt-nav .dropdown-menu>ul>li>a, .dropdown-menu>ul>li>a{
background-color: transparent;
color: #f9dd04;
-moz-transition: padding 0.3s ease-in;
-o-transition: padding 0.3s ease-in;
-webkit-transition: padding 0.3s ease-in;
transition: padding 0.3s ease-in;
padding: inherit;
}
.floridabt-nav .dropdown-menu>ul>li>a:focus, .dropdown-menu>ul>li>a:hover{
color: #222222;
padding: 10px;
}
<div class="floridabt-nav">
<div class="dropdown-menu">
<ul>
<li>
PADDING TRANSITION
</li>
</ul>
</div>
</div>

Text baseline different on IE

I have the following CSS to control three a tags which should have vertically central text, however they appear at the top of the button. It's easier to see result.
CSS Code:
color: #fffae6;
border: 1px solid #fff;
outline: 4px solid #242424;
-moz-transition: background 500ms ease-in-out;
-ms-transition: background 500ms ease-in-out;
-o-transition: background 500ms ease-in-out;
transition: background 500ms ease-in-out;
padding: 5px 0;
-webkit-transition: background 500ms ease-in-out;
background: #242424;
font-size: 1.7em;
display: block;
margin: 0 15px;
In chrome:
In IE:
Any ideas?
you have to use both the height and line-height property to achieve the same effect in IE.
Check the DEMO.
Please use line-height, as per your height of the button. I hope it will work

CSS transition not working in IE

I cant get this transition working in IE or Firefox, It looks fine in Safari and Chrome.
The opacity shows but is instant.
To me the below CSS looks right and I can't see any reason that it would work in either IE or firefox.
I've tried this using -ms-transition and it yields the same results, but the site uses CSS3 anyway so shouldn't need the -ms- anyway from what I've read.
Any light that can be shed would be greatly appreciated!
Ben
CSS:
.XMABAN {
height: 153px;
width: 230px;
background-color:rgb(127,0,25);
padding: 0;
vertical-align: top;
}
.XMABAN a {
height: 153px;
width: 230px;
text-decoration:none;
}
.XMABAN a:hover {
text-decoration:none;
}
.XMABAN img {
opacity: 1;
transition: opacity 0.70s ease-in-out;
-moz-transition: opacity 0.70s ease-in-out;
-webkit-transition: opacity 0.70s ease-in-out;
-o-transition: opacity 0.70s ease-in-out;
}
.XMABAN a:hover img {
opacity: 0.30;
transition: opacity 0.25s ease-in-out;
-moz-transition: opacity 0.25s ease-in-out;
-webkit-transition: opacity 0.25s ease-in-out;
-o-transition: opacity 0.25s ease-in-out;
}
.XMABAN span {
position: relative;
left: 0%;
top: -62%;
font-weight:bold;
font-size:20pt;
color:#404040;
transition: color 0.70s ease-in-out;
-moz-transition: color 0.70s ease-in-out;
-webkit-transition: color 0.70s ease-in-out;
-o-transition: color 0.70s ease-in-out;
}
.XMABAN a:hover span {
color:#FFF0F5;
transition: color 0.25s ease-in-out;
-moz-transition: color 0.25s ease-in-out;
-webkit-transition: color 0.25s ease-in-out;
-o-transition: color 0.25s ease-in-out;
}
HTML:
<tr>
<td style="width: 33%;">
<div class="XMABAN" style="margin: 10px 0px 5px 0px;">
<a class="DSPI" href="online.asp">
<img src="../images/PRM_220.jpg">
<span>TEXT</span>
</a>
</div>
</td>
</tr>
CSS Transitions are not supported in IE9 or lower. They are supported in IE10, however, and the CSS you've included does work correctly in IE10.
I can only assume you're using IE10 with IE9 standards to test this, which is why the transition isn't working. To change this, simply set IE's Document Mode to Standards:
It's also worth noting that you should always include vendor prefixing before the intended CSS property. Specifying transition before -webkit-transition, for instance, will tell WebKit-based browsers to use the prefixed version instead of the actual version, and there may be differences in how each are handled. Change your CSS to:
-moz-transition: ...;
-webkit-transition: ...;
-o-transition: ...;
transition: ...;

Why Does The Text Fade but Not The Image?

Heres a visual: http://cl.ly/image/2L3g1d0W1r1Y
The text fades fine, but the image on the left is instant and doesn't fade ad the same time as the text. How do I get them to fade in at the same time for all browsers? It seems to work fine in chrome, but not in Firefox or Safari.
I'm a little confused by whats going on, but heres my html:
<ul class="action">
<li><a class="visit-site" href="http://google.com">Visit Site</a></li>
<li><a class="back-to-top" href="#portfolio">Back to top</a></li>
</ul>
and here is the css:
ul.action a.visit-site {
background: transparent url('../images/arrow-small-right-rest.png') no-repeat 0 2px;
padding-left: 18px;
color: #57585a;
-webkit-transition: 0.5s all ease;
-moz-transition: 0.5s all ease;
transition: 0.5s all ease;
-o-transition-duration: 0.5s all ease;
}
ul.action a.visit-site:hover {
background: transparent url('../images/arrow-small-right-over.png') no-repeat 0 2px;
color: #3ee1df;
}
With Sprite:
ul.action a.back-to-top{
background: transparent url('../images/sprite.png') no-repeat 0 2px;
padding-left: 18px;
width: 13px;
height: 13px;
color: #57585a;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
-webkit-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
transition: all 0.5s ease;
}
ul.action a.back-to-top:hover{
background-position: 0 -63px;
color: #3ee1df;
}
If your using something like jQuery with your overall design and development you can "animate" the "opacity" of the whole UL element you have, which should create the transition you want.
But opacity isn't supported in all browsers more so the older ones. There are cross browser solutions to it, but in all you want to adjust the opacity to create the transparency effect