Why is my CSS transition ending abruptly on mouse-out? - css

I was just testing few CSS transitions( I am beginner in CSS ). All of the transitions are going smooth. But in one of the transition, when mouseover is done transition plays smoothly, and as soon as you do a mouse out it abruptly ends. In all other cases, mouseover and mouseout both are playing fine.
What is the reason why the transition is ending in such manner? How to fix it? ( Fixed: Thanks to #Edwin ). Now, please explain Why it is not working with no changes.
jsbin: http://jsbin.com/oposof , http://jsbin.com/oposof/5 ( I am concerned about the first transition 'Triangle' ).
#container1 > div.triangle {
border-bottom: 80px solid red;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
width: 0px;
height: 0px;
-webkit-transition: all 1.2s ease-in-out;
}
#container1 > div.triangle:hover {
border-top: 80px solid green;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
}
#container1 > div.triangle:active {
border-left: 80px solid blue;
border-right: 60px solid transparent;
}
#container2 > div.testt {
color: red;
-webkit-transition: all 1s ease-in-out;
}
#container2 > div.testt:hover {
color:yellow;
}
#container3 > div.circle {
border-radius: 70px;
width: 100px;
height: 100px;
background: red;
-webkit-border-radius: 50px;
-webkit-transition: all 1.2s ease-in-out;
}
#container3 > div.circle:hover {
-webkit-border-radius: 20px;
-webkit-transform: rotate(-45deg);
}
I have used -webkit- , so the above demo will work only on chrome and safari. Added -moz- Now, you can test it on Mozilla too ( hopefully in IE as well ). http://jsbin.com/oposof/5

It seems the abruptness is due to the fact that by default it does not have a border on top, then on hover it suddenly has border on top. So in mouseout, instead of transitioning, what its doing is hiding the top border because there was no initial value to reference for transition.
Try this:
#container1 > div.triangle {
border-bottom: 80px solid red;
border-top: 0 solid green;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
width: 0px;
height: 0px;
-webkit-transition: all 1.2s ease-in-out;
}

Related

CSS transition not applying to <a> tag

I am trying to create a transition for an "a" tag using the below code (written in SASS), however, the transition doesn't seem to apply. On hover, it immediately adds the bottom border and when removing the cursor, there is a second delay before removing the border without a transition.
a {
position: absolute;
top: 1em;
left: 1em;
color: white;
font-weight: 500;
display: flex;
align-items: center;
text-decoration: none;
border-bottom: white 0px solid;
transition: all 2s ease-in-out;
&:hover {
border-bottom: white 1px solid;
}
}
Any help would be much appreciated.
The transition from 0px to 1px is just one step. If you want to let the border appear try to use the opacity of the border. Like:
border-bottom: rgba(255,255, 255,0) 1px solid;
and on hover:
border-bottom: rgba(255,255,255,1) 1px solid;
a {
position: absolute;
top: 1em;
left: 1em;
color: red;
font-weight: 500;
display: flex;
align-items: center;
text-decoration: none;
border-bottom: rgba(255,0,0,0) 1px solid;
transition: all 2s ease-in-out;
}
a:hover {
border-bottom: rgba(255,0,0,1) 1px solid;
}
A Link

CSS border animation not working on object

On a website, I was creating an object that that had a border animation on it. I had searched this question a lot of times on Stack Overflow and google, but no solution worked. My animation animated the border:
.object-color {
-webkit-animation: color 1.5s linear infinite alternate both;
animation: color 1.5s linear infinite alternate both;
}
#-webkit-keyframes color{
14.3% {
color: red;
background-color: #e0ffff !important;
padding-right: 5px !important;
border: 1px solid green !important;
}
28.6% {
color: green;
background-color: #e0ffff !important;
padding-right: 5px !important;
border: 1px solid red !important;
}
100% {
color: green;
background-color: #e0ffff !important;
padding-right: 5px !important;
border: 1px solid red !important;
}
}
However, when it was applied, the border didn't animate and had no color. Any help would be great, thanks!
The problem is with your use of !important inside of keyframes. Simply removing the !important declarations will cause your animation to work:
.object-color {
-webkit-animation: color 1.5s linear infinite alternate both;
animation: color 1.5s linear infinite alternate both;
}
#-webkit-keyframes color {
14.3% {
color: red;
background-color: #e0ffff;
padding-right: 5px;
border: 1px solid green;
}
28.6% {
color: green;
background-color: #e0ffff;
padding-right: 5px;
border: 1px solid red;
}
100% {
color: green;
background-color: #e0ffff;
padding-right: 5px;
border: 1px solid red;
}
}
<div class="object-color">Hi</div>
Hope this helps! :)

CSS border won't animate

For some reason, when I hover over the div, the border animates properly, but mousing off of it produces no transition. What am I missing?
http://codepen.io/anon/pen/XbPbvr
HTML:
<div class="test">
Test
</div>
LESS:
.test {
background: #eee;
border-bottom: none;
width: 300px;
height: 300px;
transition: border 100ms ease-out;
&:hover {
border-bottom: 5px solid black;
transition: border 100ms ease-out;
}
}
If you truly want no border, you can animate the color to transparent and the length to 0:
.test {
background: #eee;
border-bottom: 0px solid transparent;
width: 300px;
height: 300px;
transition: border 100ms ease-out;
}
.test:hover {
border-bottom: 5px solid black;
}
<div class="test">
Test
</div>
You can't animate to border-bottom: none, change that to border-bottom: RGBA(0,0,0,0) (or perhaps border-bottom: transparent if that works).
You also don't need "transition: border 100ms ease-out" in the hover scope.
Border can't be none. Try this:
.test {
background: #eee;
border-bottom: 5px solid transparent;
width: 300px;
height: 300px;
transition: border 100ms ease-out;
&:hover {
border-bottom: 5px solid black;
transition: border 100ms ease-out;
}
}

Firefox and Opera rendering border incorrectly

I have created a circular menu using trapezoids made with pure CSS, but when I rotate them, Firefox shows a line in both sides and, on Opera, all trapezoids have a weird background/border-color, kind of transparent. The trapezoids look like this.
.trapezoid {
width: 100px; height: 0px;
margin: 55px auto 0 auto;
border-bottom: 140px solid black;
border-left: 35px solid transparent;
border-right: 35px solid transparent;
transition: rotate (100deg);
}
Chrome and IE9 are OK.
How can I find a way to fix this?
You'll want to use -moz for Firefox; -o for Opera. Those are the extensions to correctly format within those browsers. A great site for shapes here.
.trapezoid
{
border-bottom: 100px solid red;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
height: 0;
width: 100px;
transform:rotate(180deg);
-moz-transform:rotate(180deg); /* Firefox 4 */
-webkit-transform:rotate(180deg); /* Safari and Chrome */
-o-transform:rotate(180deg); /* Opera */
}
Also I'm not sure if your trying to alter an effect of some sort; but the transition code would look like this:
transition:width 2s, height 2s;
-moz-transition:width 2s, height 2s, -moz-transform 2s; /* Firefox 4 */
-webkit-transition:width 2s, height 2s, -webkit-transform 2s; /* Safari and Chrome */
-o-transition:width 2s, height 2s, -o-transform 2s; /* Opera */
Just add the transition before hand; then throw the transform on a hover. If your trying to add it like a button. Hopefully that helps.
I've used Firebug to view some additional data; with Firefox 16.02 this code worked:
.trapezium
{
height: 0px;
width: 80px;
border-bottom-width: 80px;
border-bottom-style: solid;
border-bottom-color: #2d9dcd;
border-left-width-value: 40px;
border-left-style-value: solid;
border-left-color-value: transparent;
border-right-width-value: 40px;
border-right-style-value: solid;
border-right-color-value: transparent;
margin-top: 30px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 10px;
}
I believe that is what you are looking for. Try that and let me know if it works.
This is happening because the vendor prefixes are missing.
Apply the vendor prefixes as following and you will get it right.
Transition property is used to set and time the transitions.
https://developer.mozilla.org/en-US/docs/CSS/Using_CSS_transitions
.trapezoid {
width: 100px; height: 0px;
margin: 55px auto 0 auto;
border-bottom: 140px solid black;
border-left: 35px solid transparent;
border-right: 35px solid transparent;
-webkit-transform: rotate(100deg);
-moz-transform: rotate(100deg);
-o-transform: rotate(100deg);
-ms-transform: rotate(100deg);
transform: rotate(100deg);
}

How to create an arrow in css3? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How to create arrow in css3?
As like this .
jsfiddle http://jsfiddle.net/BdSP4/1/
--- SEE DEMO ----
<div class="triangle-left">
<div></div>
</div>​
.triangle-left {
border-color: transparent black transparent transparent;
border-style: solid;
border-width: 20px;
width: 0;
height: 0;
}
.triangle-left div
{
border-color: transparent white transparent transparent;
border-style: solid;
border-width: 10px;
width: 0;
height: 0;
position:relative;
top:-9px;
left:0px;
}​
This is a triangle with a white triangle positioned inside, giving the appearance of an arrow. For more information on CSS3 triangles see here:
http://jonrohan.me/guide/css/creating-triangles-in-css/
See JsFiddle
HTML
<div class="angle"></div>
CSS
.angle:after { /* Thanks to :after just one div is necessary */
content: '.';
border-top: 20px solid #000; /* NW triangle gap */
border-bottom: 20px solid #000; /* SW triangle gap */
border-left: none;
border-right: 20px solid transparent; /* W triangle */
position: relative;
left: 20px;
}
.angle {
font-size: 0px; line-height: 0%; width: 0px; /* Necessary to not screw up the layout */
border-top: 20px solid transparent; /* NE triangle gap */
border-bottom: 20px solid transparent; /* SE triangle gap */
border-left: none;
border-right: 20px solid #000; /* E triangle */
}
Update: Smaller version
These are 2 overlapping triangles. One is black, one is white.
JsFiddle
Same HTML, different CSS
.angle:after {
content: '.';
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: none;
border-right: 10px solid white;
position: relative;
left: 5px;
}
.angle {
font-size: 0px; line-height: 0%; width: 0px; /* Necessary to not screw up the layout */
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: none;
border-right: 10px solid #000;
}
You don't have to use CSS 3 - create it with an HTML entity:
<span>‹</span>
Just adding alternative using CSS3's rotate
Demo
CSS
.arrow { width: 20px; height: 20px; overflow: hidden; }
.arrow span {
display: block;
border: 4px #000 solid;
background: #fff;
width: 14px;
height: 14px;
float:right;
margin-right: -12px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
filter: progid:DXImageTransform.Microsoft.Matrix(
M11=0.7071067811865476, M12=-0.7071067811865475, M21=0.7071067811865475, M22=0.7071067811865476, sizingMethod='auto expand');
zoom: 1;
}
HTML
<div class="arrow"><span></span></div>

Resources