CSS transition with background gradient - animation

I'm learning about animations/transitions with CSS3, but in this code the transition don't worked... why?
HTML:
<div id="test">
</div>
CSS:
#test {
background-color: #333;
background-image: -webkit-linear-gradient(top, #333, #666);
width: 100px;
height: 100px;
-webkit-transition: background 1s linear;
}
#test:hover {
background-image: -webkit-linear-gradient(top, #666, #999);
}
http://jsfiddle.net/LLRfN/

This works for me as it should intended. A couple things, this will only work in google chrome if you want it to work in other browsers:
Here is a generator
Here is an explanation
edit
Sorry I didn't realize there was a transition property in there. After doing some googling and trying some stuff out on my own, it is pretty clear that transitions on background gradients isn't possible... yet.
Here is a good article on how to get it to work with a little bit of a hack
http://nimbupani.com/some-css-transition-hacks.html

its working fine on me. have you wrapped the css file with tag?
<style>
#test {
background-color: #333;
background-image: -webkit-linear-gradient(top, #333, #666);
width: 100px;
height: 100px;
-webkit-transition: background 1s linear;
}
#test:hover {
background-image: -webkit-linear-gradient(top, #666, #999);
}
</style>
<div id="test">
</div>

It worked for me, Also I can point you to the CSS3 playground where you can check it on the fly CSS3 Playground

Gradient transition can by done with little bit of "cheating". I am definitely not pro in css stuff (and I am new here so don't hate me fast :D ), but just place to divs on top of each other, one with opacity 1 and second with 0.
(Each div has set different gradients) On hover, change opacity from 1 to 0 and vice versa.
Set timing function and however these divs are placed on each other z-index property do the rest.
(Optimized for Safari) Maybe rookie way, but this works (surprisingly) perfectly:
#divgradient1
{
z-index:-1;
height:100px;
background: -webkit-linear-gradient(90deg, red, blue);
background: -o-linear-gradient(90deg, red, blue);
background: -moz-linear-gradient(90deg, red, blue);
background: linear-gradient(90deg, red, blue);
opacity:1;
transition:background,opacity,z-index;
-webkit-transition:background,opacity,z-index ;
transition-duration: 1s;
-webkit-transition-duration: 1s;
}
#divgradient1:hover{
z-index:-1;
opacity:0;
transition:background,opacity,z-index;
-webkit-transition:background,opacity,z-index;
transition-duration: 1s;
-webkit-transition-duration: 1s;
}
#divgradient2:hover{
opacity:1;
z-index:2;
background: -webkit-linear-gradient(-90deg, red, blue);
background: linear-gradient(-90deg, red, blue);
transition:background,opacity,z-index;
-webkit-transition:background,opacity,z-index;
transition-duration: 1s;
-webkit-transition-duration: 1s;
}
#divgradient2
{
z-index:1;
opacity:0;
height:100px;
background: -webkit-linear-gradient(-90deg, red, blue);
background: linear-gradient(-90deg, red, blue);
transition:background,opacity,z-index;
-webkit-transition:background,opacity,z-index;
transition-duration: 1s;
-webkit-transition-duration: 1s;
}
and whatever-it-should-look-like divs:
<div id="divgradient1" style="position:absolute;width:100px;"></div>
<div id="divgradient2" style="position:absolute;width:100px;"></div>

Related

Latest opera won't hide the overflow while using border-radius property

while using border-radius Opera won't actually hide the overflowing parts of elements. I already tried to apply things I managed to find in similar threads, such as defining the border style or paying attention to positioning with absolute and relative parameters. It is still not working though.
html
<div class="node">
<div class="skill skill1"></div>
<div class="skill skill2"></div>
<div class="skill skill3"></div>
<div class="skill skill4"></div>
</div>
css
.node {
position: relative;
width: 250px;
height: 250px;
opacity: 0.9;
border-radius: 50%;
overflow: hidden;
left: -60px;
border: solid 1px transparent;
}
.skill {
position: absolute;
top: 0;
left: 0;
width: 50%;
height: 50%;
transform-origin: 100% 100%;
-webkit-transform-origin: 100% 100%;
}
.skill1 {
background-color: #26ac79;
-webkit-transform: rotate(90deg) skewX(45deg);
transform: rotate(90deg) skewX(45deg);
}
.skill2 {
background-color: #25765f;
-webkit-transform: rotate(135deg) skewX(45deg);
transform: rotate(135deg) skewX(45deg);
}
.skill3 {
background-color: #25313f;
-webkit-transform: rotate(180deg) skewX(45deg);
transform: rotate(180deg) skewX(45deg);
}
.skill4 {
background-color: #25193d;
-webkit-transform: rotate(225deg) skewX(45deg);
transform: rotate(225deg) skewX(45deg);
}
Here's the fiddle:
http://jsfiddle.net/Mu9Ar/
Thanks for any help.
Actually the code you provided works in latest Opera with Blink engine, so I guess you can leave your code as is. However if you need it to work in versions up to 12.16 and your page background is white, what you can do is to put .png overlay over your chart which will clip the chart, just like webdevelopers did in old days when there were no border-radius:)
According to the W3 specification:
http://www.w3.org/TR/css3-background/#corner-clipping
A box's backgrounds, but not its border-image, are clipped to the
appropriate curve (as determined by ‘background-clip’). Other effects
that clip to the border or padding edge (such as ‘overflow’ other than
‘visible’) also must clip to the curve. The content of replaced
elements is always trimmed to the content edge curve.
It appears that Firefox implemented the spec correctly by clipping the content to the edge of the curve when using overflow: hidden.
However, Opera is not compliant on this detail.
As an aside, if you add border-radius property to an img element, the image will be clipped correctly.
At this moment, there is no work-around that I know of unless you try HTML5 canvas.

Reflecting part of an image using CSS3

At the moment I have this image:
What I've been asked to do is to give it this effect:
Forget about the background color - notice the reflection of part of the image underneath, still the same color but with an opacity-style effect on it.
I have tried using opacity, and webkit-reflection in CSS3 but have had no luck.
I've now taken that code out as it doesn't work, I'm just left with the original image:
.infrareporting_host_0 {
background: url("../interface/infrareporting/hostLightGreen.png") no-repeat scroll 0 0 transparent;
}
Please remember:
I only want exactly what is shown - a lower section of the image reflecting, NOT the whole image reflecting
How can I fade the opacity of the reflected image ONLY? the normal one I want to stay the same but fade the reflection
A cross-browser solution is best (atm I can only do it in chrome)
Update
So far my code is reflecting properly in chrome only but opacity is not working correctly. I have this:
-webkit-box-reflect: below -3px -webkit-gradient(linear, left top, left bottom, from(transparent), color-stop(.7, transparent), to(white));
you can do as following :
html :
<div class="image-block">
<img src="http://i.stack.imgur.com/mbf9p.png" alt="" />
<div class="reflection">
<img src="http://i.stack.imgur.com/mbf9p.png" alt="" />
<div class="overlay"></div>
</div>
</div>​
css :
.image-block { width:78px; margin:0px 10px; float:left; }
.reflection { position:relative; }
.reflection img {
-webkit-transform: scaleY(-1);
-moz-transform: scaleY(-1);
-ms-transform: scaleY(-1);
-o-transform: scaleY(-1);
transform: scaleY(-1);
filter: flipv; opacity:0.20;
filter: alpha(opacity='20');
}
.overlay { position:absolute; top:0px; left:0px; width:78px; height:120px;
background-image: -moz-linear-gradient( center bottom, rgb(255,255,255) 60%, rgba(255,255,255,0) 75%);
background-image: -o-linear-gradient( rgba(255,255,255,0) 25%, rgb(255,255,255) 40%);
background-image: -webkit-gradient( linear, left bottom, left top, color-stop(0.60, rgb(255,255,255)), color-stop(0.75, rgba(255,255,255,0)));
filter: progid:DXImageTransform.Microsoft.Gradient( gradientType=0, startColor=0, EndColorStr=#ffffff);
}
​
check live demo here : demo
You can use CSS 3 for it:
.reflect {
-webkit-box-reflect: below 0
-webkit-gradient(linear, left top, left bottom, from(transparent), color-stop(0.5, transparent), to(white));
}
Or alternatives like this one:
http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/cross-browser-css-reflections-glows-and-blurs/
Use this code:
.infrareporting_host_0::before,
.infrareporting_host_0::after
{
content: "";
position: absolute;
top: 100%;
z-index: -1;
width: inherit;
height: inherit;
display: block;
}
.infrareporting_host_0::before
{
background: inherit;
}
For more info, see Crossbrowser CSS3 Reflections.

css3 border radius animation transition in safari not working

Trying to have a css3 ease transition work on border radius of an image in Safari.
It just kinda blinks into the hover state instead of smooth transition.
Any help is much appreciated. My code is below:
CSS:
.all a:hover img {
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
filter: alpha(opacity=100);
-moz-opacity:1;
-khtml-opacity: 1;
opacity: 1;
-webkit-filter: grayscale(0%);
}
.all a img {
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
width: 50%;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
filter: alpha(opacity=90);
-moz-opacity:0.9;
-khtml-opacity: 0.9;
opacity: 0.9;
}
.all a img {
-moz-transition: all .3s ease;
-webkit-transition: all .3s ease;
-o-transition: all .3s ease;
transition: all .3s ease;
}
.all a img {
-webkit-filter: grayscale(100%);
transition: border-radius .3s ease;
-moz-transition: -moz-border-radius .3s ease,border-radius .3s ease;
-webkit-transition: -webkit-border-radius .3s ease,border-radius .3s ease;
}
HTML:
<ul class="thumbs">
<li class="all identity">
<img src="https://imjoeybrennan.com/images/logos_t.jpg" alt="Logos"/>
</li>
</ul>
Link to the site:
https://imjoeybrennan.com
The following applied to the parent element with the border radius applied to kick webkit back into line for me:
-webkit-mask-image: -webkit-radial-gradient(white, black);
Another option is to wrap the element in two border radius parents.
Seems hacky to me, but far better than the double wrap option – interested to hear other solutions.
This is a simple fix, Safari does not support the transition from pixels to percentages. If you change your hover styles from 50% to 100px you will see that your transitions will work smoothly.
.all a:hover img {
-webkit-border-radius: 100px;
-moz-border-radius: 100px
border-radius: 100px;
}
You may want to set them to any value that is double the height and width of your images to ensure they will always be rounded when hovered.

Fade on hover with CSS3

Can anyone let me know why my element will not fade in?
The background image properly animates, but the .home class just appears rather than fading in?
Thanks, code snippet is below.
#home {
width:35px;
height:35px;
float:left;
margin:20px 20px 0 20px;
transition:background-position .2s ease;
-webkit-transition: background-position .2s ease;
-moz-transition: background-position .2s ease;
background-image:url('images/icons.png');
}
#home > .home {
position:absolute;
display:none;
margin-top:40px;
opacity:0;
transition:opacity 3s linear;
}
#home:hover > .home {
display:block;
opacity:1;
}
#home:hover {
background-position:0px 35px;
}
<!-- END STYLE START HTML -->
<div id="home"><div class="home">HOME</div></div>
Add transition on hover as well.
#home:hover > .home {
display:block;
opacity:1;
transition:opacity 3s linear;
}
For cross-browsing transition add:
-moz-transition ...
-webkit-transition ...
-o-transition ...
-ms- is not supported.
From W3Schools: "The transition property is not supported in any browsers.". Instead, use the specific transition properties for Firefox, Chrome, Safari and Opera: http://www.w3schools.com/cssref/css3_pr_transition.asp
IE does not support this at all.
If you want real working transitions, you should consider using a javascript library that supports animations like JQuery.

CSS Fade Between Background Images on Hover

Is there a way that I can do the following?
I have a transparent png sprite that shows a standard picture on the left, and a picture for the :hover state on the right.
Is there a way that I can have the image fade from the left image into the right image on :hover using only css3 transitions? I've tried the following, but it doesn't work:
li{-webkit-transition:all 0.5s linear; -moz-transition:all 0.5s linear; -o-transition:all 0.5s linear; transition:all 0.5s linear;}
li{background:url(/img/sprites.png) 0 -50px no-repeat;}
li:hover{background:url(/img/sprites.png) 0 -150px no-repeat;}
Now, the above does animate the background, it pans the image across. What I'd like instead of a pan is a fade or dissolve effect.
UPDATE: I ended up having to create two elements and just animate the opacities separately. It's a tad messy because I have to specify the exact margins of each element, but I guess it'll work. Thanks for everyones help :)
The latest news on this topic:
Chrome 19 and newer supports background-image transitions:
Demo:
http://dabblet.com/gist/1991345
Additional info:
http://oli.jp/2010/css-animatable-properties/
You haven't specified any code to do the actual transition.
http://css3.bradshawenterprises.com/cfimg1/
Try this out in your hover style:
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
-ms-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
Take a look at this: http://jsfiddle.net/j5brM/1/
I think this suits all your needs and its a little bit less complicated.
I don’t think you can change the opacity of just background images in CSS, so unless you have two separate elements for the background image (one for each position of the sprite) and change the opacity of both of them on hover, I think you’re stuck.
li{background:url(/img/sprites.png) 0 -50px no-repeat; background:rgba(80, 125, 200, 0.55);}
li:hover{background:url(/img/sprites.png) 0 -150px no-repeat; background:rgba(100, 125, 175, 0);}
should be
li{background:url(/img/sprites.png) 0 -50px no-repeat; background-color:rgba(80, 125, 200, 0.55);}
li:hover{background:url(/img/sprites.png) 0 -150px no-repeat; background-color:rgba(100, 125, 175, 0);}
not sure if that fixes it or not though.
I know this may be a tad late. But I was struggling with the same issue for a long time. Also with transparent sprites many solutions don't seem to work.
What I did is this
HTML
<div class="sprite-one">
<span class="foo"></span><span class="zen"></span>
</div>
CSS
.sprite-one {
height: 50px
width: 50px
}
.sprite-one span {
width: 50px;
height: 50px;
display: block;
position: absolute;
}
.foo, .zen {
background-image: url(sprites.png) no-repeat;
-webkit-transition: opacity .6s ease-in-out;
-moz-transition: opacity .6s ease-in-out;
-o-transition: opacity .6s ease-in-out;
transition: opacity .6s ease-in-out;
}
.foo {
background-position: 0 0;
opacity: 1;
}
.zen {
background-position: -50px 0;
opacity: 0;
}
.sprite-one:hover .foo {
opacity: 0;
}
.sprite-one:hover .zen {
opacity: 1;
}
This is a pure css way & has a bit of a lot of coding.. but seems be the only way I achieved the desired effect! Hope people that also stumble onto this can find some help from this!
<li class="image transition"></li>
css:
.image{
background-image: url("some/file/path.png");
background-repeat: no-repeat;
width: XXpx;
height: XXpx;
background-position: center center;
background-size: cover;
}
/* DRY */
.transition{
transition: background 0.6s;
-webkit-transition: background 0.6s;
}
.image:hover{
background-image: url("some/file/path_hoverImage.png");
}
CSS:-
li {
background: url(http://oakdale.squaresystem.co.uk/images/solutions.png) no-repeat left center;
background-size: 89px;
padding: 54px 0 54px 130px;
webkit-transition:all 0.5s linear;
-moz-transition:all 0.5s linear;
-o-transition:all 0.5s linear;
transition:all 0.5s linear;
}
li:hover {
background-size: 50px
}

Resources