I have a simple button, that I want to scale up by 10% when the user hovers on it.
I tried to achieve that by using css3 "transform: scale(1.1);" together with "transition: all .3s ease-in-out;".
It scales the button up, but also causes the text to flicker in the process. I tested it in Chrome, FF and IE - all had the same issue.
CSS:
a {
display: inline-block;
padding: 30px;
margin-top: 10%;
margin-left: 15%;
font-size: 20px;
color: #fff;
background-color: #000;
text-decoration: none;
transition: all .3s ease-in-out;
}
a:hover {
-moz-transform: scale(1.1);
-webkit-transform: scale(1.1);
-o-transform: scale(1.1);
transform: scale(1.1);
}
Example: https://jsfiddle.net/Lfwnejkc/1/
I tried to find a solution and finally managed to fix it in Chrome by adding "backface-visibility: hidden;" to the button. The text is now bit blurrier but thats alright. Unfortunately for FF and IE this doesn't work and text inside the button is still flickering when it scales up.
a {
display: inline-block;
padding: 30px;
margin-top: 10%;
margin-left: 15%;
font-size: 20px;
color: #fff;
background-color: #000;
text-decoration: none;
transition: all .3s ease-in-out;
backface-visibility: hidden;
}
a:hover {
-moz-transform: scale(1.1);
-webkit-transform: scale(1.1);
-o-transform: scale(1.1);
transform: scale(1.1);
}
Example: https://jsfiddle.net/Lfwnejkc/2/
I spent half a day yesterday googling around and trying to fix it. Unfortunately so far I haven't been successful.
Has anyone encountered such a problem and what is the best way to fix it?
Not perfect, but somehow better, is to move the element in the z plane, and get the zoom effect as a result of the perspective
a {
display: inline-block;
padding: 30px;
margin-top: 10%;
margin-left: 15%;
font-size: 20px;
color: #fff;
background-color: #000;
text-decoration: none;
transition: all 1s ease-in-out;
transform: perspective(1000px) translateZ(0px);
}
a:hover {
transform: perspective(1000px) translateZ(300px);
}
BUTTON
Related
So i made a simple button with a perspective pseudo element that flips on hover.
This works perfectly well on android and pc, but on iphone/ipad the text is only visible in the upper half.
Also tried adding a span for the text and position it above the stack, same result.
Does anyone know how to fix this?
Couldn't find a similar question on stack so far, but should be fixable i reckon.......
PS: i use scss, so it converts including -webkit and other variants..
This is how it looks on appetize.io (and real iphone):
.btn {
position: relative;
display: inline-block;
cursor: pointer;
padding: 12px 20px;
margin: 10px 10px;
text-decoration: none;
-webkit-perspective: 500px;
perspective: 500px;
color: #fff;
-webkit-transition: all .4s ease-in;
transition: all .4s ease-in;
z-index: 10;
line-height: 20px;
overflow: visible;
}
.btn:after {
content: '';
position: absolute;
width: 100%;
height: 100%;
background-color: #f00;
border-radius: 12px;
left: 0;
-webkit-perspective: 500px;
perspective: 500px;
-webkit-transform: translateY(-50%) rotateX(45deg);
transform: translateY(-50%) rotateX(45deg);
min-height: 20px;
top: 50%;
z-index: -10;
-webkit-transition: all .4s ease-out;
transition: all .4s ease-out
}
.btn:hover:after {
color: #fff;
-webkit-transform: translateY(-50%) rotateX(-135deg);
transform: translateY(-50%) rotateX(-135deg);
background-color: #000
}
<div class="btn">this is unreadable on ios?</div>
I have a link ("a" tag) in my css document, and I have an animation that scales a bottom border out from the center to both ends of the link. I want the animation to scale from the left side and stretch to the right
I have tried using a negative to positive translation on it, but that wasn't looking like I want it to. I can't seem to find any good articles on here, or any other website.
a:link:after
{
content: "";
display: block;
border-bottom: 2px solid white;
transform: scaleX(0);
transition: transform .2s ease-out;
}
a:hover:after
{
transform: scaleX(1);
}
The negative to positive translation doesn't hide the part of the border that hasn't been animated in yet, so there is just a random border to the left of the link.
You can use the translate property in combination with scale.
a {
font-size: 24px;
text-decoration: none;
position: relative;
color: black;
overflow: hidden;
display: inline-block;
}
a:after {
content: "";
background: black;
height: 2px;
transform: translate3d(-100%, 0, 0) scale(0);
transition: transform .2s ease-out;
position: absolute;
left: 0;
right: 0;
bottom: 0;
}
a:hover:after {
transform: translate3d(0, 0, 0) scale(1);
}
LINK
I am trying to make an icon rotate on mouse hover but can't get it to work.
I couldn't find a solution on the internet.
This is what I've tried so far:
#import url('https://fonts.googleapis.com/icon?family=Material+Icons');
.material-icons:hover {
-webkit-transform: rotate(180deg);
-ms-transform: rotate(180deg);
-o-transform: rotate(180deg);
transform: rotate(180deg);
}
button.c-accordion {
background-color: #eee;
color: #444;
cursor: pointer;
padding: 5px;
width: 50%;
border: none;
border: 1px solid #CBCBCB;
text-align: left;
outline: none;
font-size: 15px;
transition: 0.4s;
}
.float-right{
float: right;
}
<button class="c-accordion">Section 2
<i class="material-icons float-right">keyboard_arrow_down</i>
</button>
Am able to find two issues,
rotate is working fine in chrome, but not working in firefox.
transition is not smooth as mentioned by others.
So for first issue changed hover pseudo from icon to button because there is an issue in firefox when <i> used inside button. For second one followed as like others by adding transition.
#import url('https://fonts.googleapis.com/icon?family=Material+Icons');
.c-accordion:hover .material-icons {
-webkit-transform: rotate(180deg);
-ms-transform: rotate(180deg);
-o-transform: rotate(180deg);
transform: rotate(180deg);
transition: all .3s ease;
}
button.c-accordion {
background-color: #eee;
color: #444;
cursor: pointer;
padding: 5px;
width: 50%;
border: none;
border: 1px solid #CBCBCB;
text-align: left;
outline: none;
font-size: 15px;
transition: 0.4s;
}
.float-right {
float: right;
}
<button class="c-accordion">Section 2
<i class="material-icons float-right">keyboard_arrow_down</i>
icon rotate on mouse hover on chrome but not on Mozilla Firefox same code work on my side on chrome
Page with buttons here: http://teamcherry.com.au/jam-games/
The effect I'm trying to achieve with the links on this page is that the button expands when hovered, with the text remaining the same size, and the text staying in the same position on the screen (so the button doesn't appear to 'move' when changing size).
After researching for a while, I've managed to achieve the desired effect using the below css, which changes the padding an margin on hover using css transition:
a.btn {
display: inline-block;
background-color: #d11b34;
color: #fff;
text-decoration: none;
font-size: 20px;
padding: 10px;
padding-right: 20px;
padding-left: 20px;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
transition: all 0.3s ease 0s;
}
a.btn:hover {
background-color: #a61529;
padding: 15px;
padding-right: 25px;
padding-left: 25px;
margin: -5px;
}
This achieves the effect, but the effect is super jittery when animating in Chrome (and possibly other browsers) and the button seems to quiver when hovering.
Is there another way to achieve this precise effect without animation jittering? Ideally in pure CSS but if JS or JQ is required then that's what I'll use.
Use hardware acceleration and add a bit more time to the animation (you can adjust if needed) and it looks nice. You can also use ease-in-out for a smoother effect. Tested in FF and Chrome
a.btn {
display: inline-block;
background-color: #d11b34;
color: #fff;
text-decoration: none;
font-size: 20px;
padding: 10px;
padding-right: 20px;
padding-left: 20px;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
transition: all 0.6s ease;
-webkit-transform: translate3d(0,0,0);
-moz-transform: translate3d(0,0,0);
-ms-transform: translate3d(0,0,0);
-o-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}
I achieved this by box-shadow
a {
transition: .2s ease;
&:hover {
box-shadow: 0 0 0 .3rem $color;
}
}
use transition scale . That is smoother solution for you :)
a.btn {
display: inline-block;
background-color: #d11b34;
color: #fff;
text-decoration: none;
font-size: 20px;
padding: 10px;
padding-right: 20px;
padding-left: 20px;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
-webkit-transform: scale(1,1);
-webkit-transition-timing-function: ease-out;
-webkit-transition-duration: 250ms;
-moz-transform: scale(1,1);
-moz-transition-timing-function: ease-out;
-moz-transition-duration: 250ms;
}
a.btn:hover {
-webkit-transform: scale(1.05,1.07);
-webkit-transition-timing-function: ease-out;
-webkit-transition-duration: 250ms;
-moz-transform: scale(1.05,1.07);
-moz-transition-timing-function: ease-out;
-moz-transition-duration: 250ms;
}
Tested in chrome console. Hope it helps :)
This question already has answers here:
Flip a 3D card with CSS
(2 answers)
Closed 6 years ago.
I'm new in CSS3, and I am interested in 3D animation with it. I have a question and hope someone can help me. Is there any way to make a card flip effect without using click events? I have searched a lot about it but could not generate results with my little experience. Please, could you help me?
You can do this with css-transitions and no Javascript at all. Using :target css attribute to detect the state of the card
CSS
a {
display: block;
margin-bottom: 10px;
padding: 10px;
width: 135px;
background: red;
border: 1px solid black;
border-radius: 10px;
color: white;
text-transform: uppercase;
text-decoration: none;
}
a.unflip { display: none; }
div.card { position: relative; }
img {
position: absolute;
width: 190px;
height: 265px;
-webkit-transition: all 1s;
-moz-transition: all 1s;
-o-transition: all 1s;
-ms-transition: all 1s;
transition: all 1s;
}
img.front { z-index: 1; }
img.back, div#flip:target img.front {
-webkit-transform: rotateY(-180deg);
-moz-transform: rotateY(-180deg);
-o-transform: rotateY(-180deg);
-ms-transform: rotateY(-180deg);
transform: rotateY(-180deg);
z-index: 0;
}
div#flip:target a.flip { display: none; }
div#flip:target a.unflip { display: block; }
div#flip:target img.back {
-webkit-transform: rotateY(0deg);
-moz-transform: rotateY(0deg);
-o-transform: rotateY(0deg);
-ms-transform: rotateY(0deg);
transform: rotateY(0deg);
z-index: 1;
}
HTML :
<div class='card' id='flip'>
<a href='#flip' class='flip'>Flip that card</a>
<a href='#unflip' class='unflip'>Flip that card</a>
<img src='https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRZNrO98qaNGRBnMuuMctzqNMsE0DeUQXelgWi2zPsKYmjD-lqn' class='front' />
<img src='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQSwcvrsqZZFqZYMPSfVGDomBaDbQc2b7A1i88kDA2P52k3VN0y7w' class='back' />
</div>
Demo here : http://jsbin.com/emolev/1/edit