I am trying to realise a nice Hover Off effect using CSS. There is a pretty good example here, but I can't reproduce this with the properties background-size and font-size.
The effect is simply to zoom in the image and the text on mouse over and come back to the original state on hover off but in a clean way (using -webkit-transition). This code fails:
.nice a {
background: url(../my_image.png) no-repeat;
background-size: 40px 37px;
font-size: 12px;
/* HOVER OFF */
-webkit-transition: background-size 2s;
-webkit-transition: font-size 2s;
}
.nice a:hover{
background: url(../my_image.png) no-repeat ;
background-size: 43px 39px;
font-size: 13px;
/* HOVER ON */
-webkit-transition: background-size 2s;
-webkit-transition: font-size 2s;
}
Any ideas?
I think the problem, with the code you provided, is there aren't enough 'steps' or 'keyframes' for the animation to run smoothly.
See this demo: http://dabblet.com/gist/3763579.
The box using your properties[one on the right], has 2 seconds on the clock to animate just one or two pixels, so there'd be an apparent delay before the artifacts jump to the next pixel. Same with animating back to place, hence the choppy, un-smooth transition.
You can use transform:scale(value);
Test it
.nice a {
font-size: 12px;
display:block;
-webkit-transition:all 2s ease;
-webkit-transform-origin:top left;
}
.nice a:hover {
-webkit-transform:scale(1.3);
}
Here is working Demo
and the tutorial to know more about background
This is another way to do it with transforms.
.nice a { -webkit-transition: font-size .2s ease-in-out; }
.nice a:hover { -webkit-transform: scale(1.1); }
example with key frames(drawback is not all the time hover, it won't stay).
#-webkit-keyframes scalar{
from{
background-size: 40px 37px;
font-size: 22px;
}
to{
background-size: 103px 79px;
font-size: 32px;
}
}
.nice2 a{
background: skyblue;
background-image:url("http://lorempixel.com/300/200/abstract");
background-repeat:no-repeat;
background-size: 40px 37px;
font-size: 22px;
color:white;
}
.nice2 a:hover{
-webkit-animation: scalar 1s;
}
upadated demo with keyframes
we have seen Three ways to do it. lets decide which best for it.
Transitions which gives smooth and nice appearance.
Transforms which blurs while growing content.
Keyframes which leads to high end but...
Choice is yours!
My bad, this works:
/* HOVER OFF */
-webkit-transition-property: background-size, font-size;
o-transition-property: background-size, font-size;
-moz-transition-property: background-size, font-size;
transition-property: background-size, font-size;
-webkit-transition-duration: 0.5s;
-o-transition-duration: 0.5s;
-moz-transition-duration: 0.5s;
transition-duration: 0.5s;
Related
I have created a button which transitions into a different colour when mouse hovers over.
I cannot figure out how to make the colour change back to its original when the mouse is no longer hovering.
I have tried many ways, which have not worked.
Is there another Psuedo-element which I could use? Any help would be really appreciated.
#cta-btn:hover {
background-color: #37A3BC;
-webkit-transition-duration: 0.5s;
transition-duration: 0.5s;
}
Add this code to your original cta-btn:
#cta-btn {
background-color: (enter your original bg color) ;
-webkit-transition-duration: 0.5s;
transition-duration: 0.5s;
}
Here's the CSS I'm using and I've tested it against the latest browsers.
.team-member {
padding: 15px;
background: #fafafa;
min-height: 150px;
width: 100%;
transition: linear background .5s;
border-radius: 3px;
overflow: auto;
}
.team-member:hover {
background: #eee;
transition: linear background .5s;
}
Also, you should also add vendor specific css prefix. For ex)
{
-moz-transition: linear background .5s;
-o-transition: linear background .5s;
-webkit-transition: linear background .5s;
transition: linear background .5s;
}
Well, I have set up an animation when someone hovers over a button, and when they do so, the background color, border radius and the font color change. When I hover over it, there is a smooth animation, however when I stop hovering, there is a very sharp animation.
Code:
.button {
text-align:center;
background:#ccc;
display:inline-block;
position:relative;
text-transform:uppercase;
margin:25px;
border:solid #B26B24;
background:none;
color:#fff;
border-top-left-radius:17px;
border-top-right-radius:17px;
border-bottom-left-radius:17px;
border-bottom-right-radius:17px;
-moz-border-radius-topleft:17px;
-moz-border-radius-topright:17px;
-moz-border-radius-bottomleft:17px;
-moz-border-radius-bottomright:17px;
-webkit-border-top-left-radius:17px;
-webkit-border-top-right-radius:17px;
-webkit-border-bottom-left-radius:17px;
-webkit-border-bottom-right-radius:17px;
}
.button:hover {
background-color:#ffffff;
color:#161616;
font-size:18px;
border-top-left-radius:75px;
border-top-right-radius:75px;
border-bottom-left-radius:75px;
border-bottom-right-radius:75px;
transition: 0.75s;
-webkit-transition: 0.75s;
-ms-transition: 0.75s;
}
.button-text {
padding:0 25px;
line-height:56px;
letter-spacing:3px;
}
Working example:
http://codepen.io/Riggster/pen/eNppgJ
Does anyone know how I stop this sharp animation from happening?
I have looked on stack overflow and the internet however all I can find is people having this issue, but with javascript or JQuery.
Thanks.
You need to set the transition declaration on the element you want to animate. Right now it is only on :hover, so the animation only occurs when hovering.
.button {
transition: 0.75s;
-webkit-transition: 0.75s;
-ms-transition: 0.75s;
/* etc. */
}
.button:hover {
/* no transition declaration */
background-color: #ffffff;
color: #161616;
font-size: 18px;
border-top-left-radius: 75px;
border-top-right-radius: 75px;
border-bottom-left-radius: 75px;
border-bottom-right-radius: 75px;
}
Updated Codepen
Image out of box. It seems that is not the right think I do. If anyone can help I would be glad.
Thank You!
Here You can find Demo
.box {
width:210px;
height:210px;
border-radius:50%;
border:3px solid yellow;
cursor: default;
overflow: hidden;
}
img{
overflow: hidden;
width:210px;
height:210px;
z-index:-1;
display: block;
position: relative;
-webkit-transition: all 0.6s ease-in-out;
-moz-transition: all 0.6s ease-in-out;
-o-transition: all 0.6s ease-in-out;
-ms-transition: all 0.6s ease-in-out;
transition: all 0.6s ease-in-out;
}
.box:hover img{
-webkit-transform: scale(2);
-moz-transform: scale(2);
-o-transform: scale(2);
-ms-transform: scale(2);
transform: scale(2);
}
It's seems the problem is only on webkit browsers. I make some research after catch that border-radius property crash the scale transition and I found this
overflow:hidden ignored with border-radius and CSS transforms (webkit only)
You have to put -webkit-mask-image: to the parent div to fix that.
-webkit-mask-image: -webkit-radial-gradient(circle, white, black);
http://jsfiddle.net/Jx8xF/16/
Edit: And have you attention, that background-size is expensive operation - see this article on Fix 4. Remove background-size CSS property if it slows down your website
http://kristerkari.github.io/adventures-in-webkit-land/blog/2013/08/30/fixing-a-parallax-scrolling-website-to-run-in-60-fps/
And finally you can see that zoomin the image is more smooth with scale() css transition method than background-size
EDIT2: code update on http://jsfiddle.net/Jx8xF/19/
Tested on Safari 5.1.7, Chrome, Mozilla, IE10, Opera, Opera Next
As you can see the Safari browser is only who have problems after first fix. For him you need to set
-webkit-transform: translateZ(0);
And that is not all. You need to group two layers for the border bug, and wrap it with another div. In code you can see the complete fix in HTML and CSS file.
This effect can be better achieved by removing the img element, and instead using the image as a background on the .box element. Then you use transition on the background-size property.
Here is a working example on CodePen. Example code below.
.box {
-webkit-transition: all 0.4s ease;
width:210px;
height:210px;
border-radius:100%;
border:3px solid yellow;
background: url('http://fc07.deviantart.net/fs71/f/2012/144/b/6/barn_owl_leather_mask_by_teonova_by_teonova-d50xl3v.jpg') center center;
background-size: 100%;
}
.box:hover{
-webkit-transition: all 0.4s ease;
background-size: 150%;
}
i have a problem with scale transforme effect and overflow on Safari.
When i used this effect on a div content, the overflow not work on a rounded container.
here my code:
.container{
width:100px;
height:100px;
border-radius: 50%;
background:none;
z-index:100;
box-shadow:
inset 0 0 0 6px rgba(255,255,255,0.6),
0 1px 2px rgba(0,0,0,0.1);
overflow:hidden;
-webkit-transition:all .9s ease-in-out; // Chrome Safari
-moz-transition:all.9s ease-in-out; // Mozilla
-o-transition:all.9s ease-in-out; // Opéra
-ms-transition:all .9s ease-in-out; // IE
transition:all.9s ease-in-out;
}
.container:hover .scaler
{
-webkit-transform: rotate(380deg) scale(11);
-moz-transform: rotate(380deg) scale(11);
-o-transform: rotate(380deg) scale(11);
transform: rotate(380deg) scale(11);
filter: alpha(opacity=0);
opacity: 0;
width:100px;
height:100px;
border-radius: 50%;
}
.scaler{
width:100px;
height:100px;
font-size:36px;
border-radius: 50%;
z-index:-999;
line-height:100px;
vertical-align:middle;
text-align:center;
background:#0066FF;
color:#CCCCCC;
-webkit-transition:all .4s; // Chrome Safari
-moz-transition:all .4s; // Mozilla
-o-transition:all .4s; // Opéra
-ms-transition:all .4s; // IE
transition:all .4s;
}
<div class="container">
<div class="scaler">HI</div>
</div>
thank you very much!!
(sorry for my bad english)
If you include -webkit-mask-image with a radial gradient on the .container class, this will create a mask which will prevent the content of the child element being shown outside the bounds of the parent. This is much like a layer mask used in a graphics application.
-webkit-mask-image: -webkit-radial-gradient(white, black);
I used clip-path to overcome this problem, as it does exactly what you'd expect: Clips anything outside the region that it defines. And it will retain your border-radius if you use content-box as the value:
.container
{
clip-path: content-box;
}
Here's a more detailed breakdown of what you can achieve with clip-path.
Edit: Removed reference to the -webkit prefix as this isn't necessary. Also, the content-box value is only valid in Safari, but this is the only browser I saw the original problem in anyway.
I came across the transform problem in Safari, and it needs an update.
My problem had to do with a counter skewed background-image in a skewed container.
The solution with
-webkit-mask-image: -webkit-linear-gradient(white, black);
works good in Safari for OS X (11.0.1), but it breaks the anti-aliasing in Chrome (62).
Safari appears to have dropped support for
clip-path: content-box;
but not for
-webkit-clip-path: content-box;
despite the inspector claims that the -webkit- prefix is not needed.
I have this problem in my really easy css file, that I want to transform a div from 75px in height and width with :hover, but it seems to only change the width.
#ich{
transition: 2s;
-moz-transition: 2s; /* Firefox 4 */
-webkit-transition: 2s; /* Safari and Chrome */
-o-transition: 2s; /* Opera */
margin-top:40%;
width:75px;
height:75px;
border-radius:35px;
background-image:url(fb.jpg) ;
background-repeat: no-repeat;
background-position: center;
text-align:center;
display:block;
}
#ich:hover{
width:300px!important;
height:300x!important;
background-size: 300px 300px;
}
The HTML is just a div with id #ich in the body part, nothing else.
height:300px!important;
you just put "300x" instead of "300px"