I have a basic CSS transition where I rotate a pseudo ::after element and increase its width on hover. However the element transition is choppy and skips most of the animation halfway through.
Issue reproduced in a Code Pen.
I've tried using -webkit-backface-visibility: hidden; to solve the issue but I cant seem to stop the transition flash. Any ideas?
Transition css:
a {
position: relative;
text-decoration: none;
color: #db421c;
-webkit-box-shadow: inset 0px 4px 0px #fff;
-moz-box-shadow: inset 0px 4px 0px #fff;
-o-box-shadow: inset 0px 4px 0px #fff;
box-shadow: inset 0px 4px 0px #fff;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
a + a {
margin-left: 20px;
}
a::after{
width: 20px;
height: 1px;
content: " ";
background: black;
position: absolute;
-webkit-transform: rotate(90deg) translate(55%, 10%);
-moz-transform: rotate(90deg) translate(55%, 10%);
-o-transform: rotate(90deg) translate(55%, 10%);
transform: rotate(90deg) translate(55%, 10%);
webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
a:last-child::after {
content: none;
}
a:hover {
color: black;
}
a:hover::after {
width: 100%;
height: 2px;
-webkit-transform: rotate(180deg) translate(100%, -20px);
-moz-transform: rotate(180deg) translate(100%, -20px);
-o-transform: rotate(180deg) translate(100%, -20px);
transform: rotate(180deg) translate(100%, -20px);
}
I isolated the issue to the translate transformation; I wasn't sure how exactly to fix it, although I have a feeling the solution is in the transform-origin property. The only working solution I was able to come up with was to use positioning in order to move the pseudo elements. The same rotation is being used, we are just making use of the absolute positioning in order to translate the elements. This method doesn't have any apparent issues given that the parent element is relatively positioned. This method should also work for elements with varying widths.
UPDATED EXAMPLE HERE - it achives the exact same effect without the choppiness.
Instead of translate(55%, 10%), use top: 10px/right: -22px
And instead of translate(100%, -20px), use top: 22px/right: 0px
Updated CSS
a::after {
width: 20px;
height: 1px;
content: " ";
background: black;
position: absolute;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
transform: rotate(90deg);
webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
top: 10px;
right: -22px;
}
a:hover::after {
width: 100%;
height: 2px;
-webkit-transform: rotate(180deg);
-moz-transform: rotate(180deg);
-o-transform: rotate(180deg);
transform: rotate(180deg);
top: 22px;
right: 0px;
}
Related
I have a button with arrows that is supposed to appear and move down when moused over. On Chrome and Firefox it works fine but when I open it up on Safari the arrows are too low- they aren't positioned correctly. I have heard about people specifying "top" and :left" but that doesn't seem to work for me. I don't know why this is but it seems to be due to the position: relative.
Code:
<a class="details" href="#scroll"> <span class="details__border--bottom">More Details</span>
</a>
<div class="top-portion__arrows">
<span class="top-portion__arrows--hide"></span>
<span class="top-portion__arrows--hide"></span>
<span class="top-portion__arrows--hide"></span>
</div>
a.details {
border: 2.5px solid white;
padding: 8px 62px;
padding-top: 11px;
font-family: 'Roboto', sans-serif;
font-size: 1.75rem;
background-color: rgba(214, 128, 0, 0.45);
color: white;
cursor: pointer;
position: relative;
-webkit-transform: translateX(-50%);
-ms-transform: translateX(-50%);
transform: translateX(-50%);
left: 50%;
top: 5%;
z-index: 1;
display: inline-block;
}
a.details:hover,
a.details:focus {
background-color: rgba(231, 147, 21, 0.25);
-webkit-transition: .5s ease-in;
-o-transition: .5s ease-in;
transition: .5s ease-in;
}
a.details:hover,
a.details:focus {
border: 3.5px solid white;
-webkit-transition: .15s;
-o-transition: .15s;
transition: .15s;
}
a.details:active {
background-color: rgba(247, 195, 100, 0.75);
-webkit-transition: .15s;
-o-transition: .15s;
transition: .15s;
}
.details__border--bottom {
display: inline-block;
padding: 2px 0px 4px;
margin: 0px 8px 0px;
position: relative;
}
.details__border--bottom:before {
content: '';
position: absolute;
width: 100%;
height: 0px;
border-bottom: 2.5px solid white;
bottom: 2px;
-webkit-transform: scaleX(0);
-ms-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: -webkit-transform 0.25s ease-in-out;
-webkit-transition: -webkit-transform 0.45s ease-in-out;
transition: -webkit-transform 0.45s ease-in-out;
-o-transition: transform 0.45s ease-in-out;
transition: transform 0.45s ease-in-out;
transition: transform 0.45s ease-in-out, -webkit-transform 0.45s ease-in-out;
}
a:hover .details__border--bottom:before,
a:focus .details__border--bottom:before {
-webkit-transform: scaleX(1);
-ms-transform: scaleX(1);
transform: scaleX(1);
}
.top-portion__arrows {
position: relative;
width: 0%;
top: 10%;
left: 51.5%;
}
.top-portion__arrows .top-portion__arrows--hide {
opacity: 0;
display: block;
width: 120px;
height: 120px;
border-bottom: 3px solid white;
border-right: 3px solid white;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
margin: -85px;
}
a.details:hover + .top-portion__arrows .top-portion__arrows--hide,
a.details:focus + .top-portion__arrows .top-portion__arrows--hide {
opacity: 1;
-webkit-animation: animate .65s ease;
animation: animate .65s ease;
}
.top-portion__arrows .top-portion__arrows--hide:hover .details__border--full,
.top-portion__arrows .top-portion__arrows--hide:focus .details__border--full {
border: 2.5px solid white;
-webkit-transition: .2s ease-in;
-o-transition: .2s ease-in;
transition: .2s ease-in;
}
#-webkit-keyframes animate {
0%{
opacity: 0;
-webkit-transform: rotate(45deg) translate(-10px,-10px);
transform: rotate(45deg) translate(-10px,-10px);
}
50%{
opacity: .5;
}
100%{
opacity: 1;
-webkit-transform: rotate(45deg) translate(0px,0px);
transform: rotate(45deg) translate(0px,0px);
}
}
#keyframes animate {
0%{
opacity: 0;
-webkit-transform: rotate(45deg) translate(-10px,-10px);
transform: rotate(45deg) translate(-10px,-10px);
}
50%{
opacity: .5;
}
100%{
opacity: 1;
-webkit-transform: rotate(45deg) translate(0px,0px);
transform: rotate(45deg) translate(0px,0px);
}
}
You can detect whether a user is browsing on safari with some javascript and then if they are browsing on safari, style the buttons a certain way by changing the margin-left and margin-top. Here is the code to detect whether the user is on safari:
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('safari') != -1) {
if (ua.indexOf('chrome') > -1) {
alert("chrome") // Chrome
} else {
alert("safari") // Safari
}
}
Edit: Your full code:
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('safari') != -1) {
if (ua.indexOf('chrome') > -1) {
} else {
document.getElementById("btn1").style.marginTop = "80%"; }
}
I need to display a text on the image using CSS. I'm doing that using H2 tag:
<h2 class="post-message">Test</h2>
Here is the code for CSS:
.post-message {
position: absolute;
bottom: 10px;
left: 10px;
background: rgba(0, 0, 0, 0.75);
padding: 4px 8px;
color: white;
margin: 0;
font: 14px Sans-Serif;
}
But the overlay effect is messing things up and here is the code:
.overlay{
overflow: hidden;
background: #000;
}
.overlay img{
-webkit-transition: -webkit-transform .3s ease-out;
-moz-transition: -moz-transform .3s ease-out;
-o-transition: -o-transform .3s ease-out;
transition: transform .3s ease-out;
}
.overlay:hover img{
-webkit-transform: scale(1.2) rotate(-5deg);
-moz-transform: scale(1.2) rotate(-5deg);
-o-transform: scale(1.2) rotate(-5deg);
-ms-transform: scale(1.2) rotate(-5deg);
transform: scale(1.2) rotate(-5deg);
opacity: 0.7;
}
I don't know how to explain what happens and I uploaded 2 screens:
This screen shows the original image without Mouse hover: https://s22.postimg.org/xrsohlcw1/without_mouse_over.jpg
On the first image you see a gray background that I don't know from where comes
The second image is the mouse over effect: that gray image is rotating according to overlay effect and is displayed at the right corner only :/
https://s22.postimg.org/a13x0ndmp/gra_color_disappears.jpg
A little red arrow will show you what happens on the second image. A help would be great! I tried all possible things that I knew, expert opinion always is the best solution. Thanks in advance!
<div class="post-thumbnail overlay">
<a href="http://example.com/comey-wikileaks/">
<img src="http://example.com/wp-content/uploads/2017/04/comey-825x510.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" width="825" height="510">
</a>
<h2 class="post-message">Test</h2>
</div>
An img has a "replaced content" layout model and basically treated as an inline element, and that includes space at the bottom by default for the bottom part of characters, so there will be a small space between the bottom of an img and the bottom of the img's container. To remove that gap at the bottom, either make the img display: block or use vertical-align: top.
If the image is rotating so far that you see the corner of it in the bottom/right corner, either increase your scale() or don't rotate as much until you can't see that anymore. I don't see it with the code you provided.
.post-message {
position: absolute;
bottom: 10px;
left: 10px;
background: rgba(0, 0, 0, 0.75);
padding: 4px 8px;
color: white;
margin: 0;
font: 14px Sans-Serif;
}
.overlay {
overflow: hidden;
background: #000;
}
.overlay img {
-webkit-transition: -webkit-transform .3s ease-out;
-moz-transition: -moz-transform .3s ease-out;
-o-transition: -o-transform .3s ease-out;
transition: transform .3s ease-out;
}
.overlay:hover img {
-webkit-transform: scale(1.2) rotate(-5deg);
-moz-transform: scale(1.2) rotate(-5deg);
-o-transform: scale(1.2) rotate(-5deg);
-ms-transform: scale(1.2) rotate(-5deg);
transform: scale(1.2) rotate(-5deg);
opacity: 0.7;
}
img {
vertical-align: top;
}
<div class="post-thumbnail overlay">
<a href="http://example.com/comey-wikileaks/">
<img src="http://kenwheeler.github.io/slick/img/fonz1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" width="825" height="510">
</a>
<h2 class="post-message">Test</h2>
</div>
You could actually put your img together with your <h2> inside a <div> and let the whole <div> rotate....
Here is an example base on what you wrote:
(obvously, there's a few things to readjust, but it's more or less what you want, I guess ^^)
.post-message {
position: absolute;
bottom: 10px;
left: 10px;
background: rgba(0, 0, 0, 0.75);
padding: 4px 8px;
color: white;
margin: 0;
font: 14px Sans-Serif;
}
.overlay{
overflow: hidden;
background: #000;
/*these two lines are new*/
display:inline-block;
position:relative;
}
/*I apply style directly on the "overlay"*/
.overlay /*img*/{
-webkit-transition: -webkit-transform .3s ease-out;
-moz-transition: -moz-transform .3s ease-out;
-o-transition: -o-transform .3s ease-out;
transition: transform .3s ease-out;
}
.overlay:hover /*img*/{
-webkit-transform: scale(1.2) rotate(-5deg);
-moz-transform: scale(1.2) rotate(-5deg);
-o-transform: scale(1.2) rotate(-5deg);
-ms-transform: scale(1.2) rotate(-5deg);
transform: scale(1.2) rotate(-5deg);
opacity: 0.7;
}
<span class="overlay">
<img src="https://www.codeproject.com/KB/GDI-plus/ImageProcessing2/img.jpg" />
<h2 class="post-message">Test</h2>
</span>
I've a burger icon, like this - when clicked it becomes a "X" using only CSS3 (website link here)
But my client are seeing something like this (only on iPad):
My question is:
1) What can be causing this?
2) How can I reproduce errors like this as I don't have an iPad and resizing the browser (developer tools) doesn't reproduce the error?
.mobile-nav {
position: fixed;
z-index: 10103;
bottom: 40%;
left: 45%;
margin-top: -230px;
pointer-events: none;
}
.mobile-nav .mobile-nav-bg {
/* this is the stretching navigation background */
position: absolute;
z-index: 10102;
top: 0;
right: 0;
width: 60px;
height: 60px;
border-radius: 30px !important;
background: #fff;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
webkit-transition: height .2s, box-shadow .2s;
-webkit-transition: height .2s, box-shadow .2s;
transition: height .2s, box-shadow .2s;
}
.mobile-nav-trigger {
position: absolute;
z-index: 10103;
top: 2px;
right: 0;
height: 60px;
width: 60px;
border-radius: 50% !important;
overflow: hidden;
white-space: nowrap;
color: transparent;
pointer-events: auto;
}
.mobile-nav-trigger span,
.mobile-nav-trigger span::after,
.mobile-nav-trigger span::before {
/* this is the hamburger icon */
position: absolute;
width: 16px;
height: 2px;
background-color: #000;
}
.mobile-nav-trigger span {
/* middle line of the hamburger icon */
webkit-transition: background-color 0.2s;
-webkit-transition: background-color 0.2s;
transition: background-color 0.2s;
left: 50%;
top: auto;
bottom: 50%;
right: auto;
webkit-transform: translateX(-50%) translateY(-50%);
-webkit-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
}
.mobile-nav-trigger span::after,
.mobile-nav-trigger span::before {
/* top and bottom lines of the hamburger icon */
content: '';
bottom: 0;
left: 0;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
webkit-transition: transform 0.2s;
-webkit-transition: -webkit-transform 0.2s;
transition: -webkit-transform 0.2s;
transition: transform 0.2s;
transition: transform 0.2s, -webkit-transform 0.2s;
}
.mobile-nav-trigger span::before {
webkit-transform: translateY(-6px);
-webkit-transform: translateY(-6px);
transform: translateY(-6px);
}
.mobile-nav-trigger span::after {
webkit-transform: translateY(6px);
-webkit-transform: translateY(6px);
transform: translateY(6px);
}
.nav-is-visible .mobile-nav-trigger span {
background-color: transparent; }
.nav-is-visible .mobile-nav-trigger span::before {
webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg); }
.nav-is-visible .mobile-nav-trigger span::after {
webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://188.166.163.149/static/theme/global/plugins/bootstrap/js/bootstrap.min.js"></script>
<script>
$(document).ready(function() {
$('nav').click(function() {
$(this).toggleClass('nav-is-visible');
});
});
</script>
<div class="box">
<nav class="mobile-nav visible-xs visible-sm nav-is-visible"><a class="mobile-nav-trigger menu-trigger" href="#0"><span aria-hidden="true"></span></a><ul><li></li></ul><span aria-hidden="true" class="mobile-nav-bg"></span></nav>
</div>
In many cases your vendor prefixes are not correct. For example:
.mobile-nav-trigger span {
...
webkit-transition: background-color 0.2s;
-webkit-transition: background-color 0.2s;
transition: background-color 0.2s;
...
}
The first statement of these 3 is not legal in any browser I know of. The first line (no dash before "webkit") needs to be removed in all cases. The other two lines are valid; and should be present in all cases.
Although I haven't tested this definitively, it certain could be causing the issue you are experiencing.
Sign up for a free Apple Developer account, Download XCode and you can run the iOS device emulator as an iPad. That will allow you to test your potential fixes. You do need a Mac, however. But, that's the only way I know how you could do it other than buying or borrowing an iPad.
I am trying to transform a button, but it is really grainy (During the transform) in firefox.
Can someone take a look, the code is below... and the js fiddle link is attached here https://jsfiddle.net/L3f9cy7g/1/
As I said. The issue is only in firefox, and I think it has something to do with anti-aliasing. We tried switching it to a 3d transform, and adjusting the z-index to prevent the firefox browser from messing with the animation. No luck so far.
<div class="closePop">
<p></p>
</div>
body{background:black;}
.closePop {
right: -5px;
top: -5px;
height: 28px;
background-color: #f68d1e;
color: white;
border-radius: 50%;
width: 29px;
text-align: center;
border-style: solid;
border-width: 2px;
vertical-align: middle;
cursor: pointer;
transform: rotate(0deg);
transition: all .3s ease-out;
}
.closePop p {
margin: 0;
margin-top: 4px;
}
.closePop:hover p:after {
content:':(';
transition:contentArea 3s ease-out rotate .3s ease-out;
-webkit-transform: rotate(0deg);
-ms-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: translateZ(1px) rotate(0deg);
}
.closePop p:after {
content: 'X';
transition: all .3s ease-out;
-webkit-transform: rotate(90deg);
-ms-transform: rotate(90deg);
-o-transform: rotate(90deg);
transform: translateZ(1px) rotate(90deg);
}
.closePop:hover {
border-radius: 0;
-webkit-transform: rotate(90deg);
-ms-transform: rotate(90deg);
-o-transform: rotate(90deg);
transform: translateZ(1px) rotate(90deg);
}
.closePop p {
transition: contentArea .3s ease-out rotate .3s ease-out;
}
Try to add a transparent outline attribute,
outline: 1px solid transparent;
This question already has answers here:
Spin or rotate an image on hover
(5 answers)
Closed 7 years ago.
I have this code to make a rotation on hover. It doesn't work at all. What's is wrong with it?
I need the complete animation of the rotation for 360ยบ
.icon-style-1 .builder-element-icon {
height: 100px;
width: 100px;
line-height: 100px;
background: blue;
line-height: 100px;
text-align: center;
margin: 0 auto;
display: block;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
color: white;
}
.icon-style-1 .builder-element-icon:hover {
background: green;
-moz-transform: rotate(360deg);
-webkit-transform: rotate(360deg);
-o-transform: rotate(360deg);
-ms-transform: rotate(360deg);
transform: rotate(360deg);
}
<div class="icon-style-1">
<span class="builder-element-icon fa fa-camera"></span>
</div>
So here you go with transition on normal element style and rotate added on hover and External DEMO HERE
.icon-style-1 .builder-element-icon{
height: 100px;
width: 100px;
line-height: 100px;
background: blue;
line-height: 100px;
text-align: center;
margin: 0 auto;
display: block;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
color: white;
/* Firefox */
-moz-transition: all 1s ease;
/* WebKit */
-webkit-transition: all 1s ease;
/* Opera */
-o-transition: all 1s ease;
/* Standard */
transition: all 1s ease;
}
.icon-style-1 .builder-element-icon:hover{
background: green;
/* Firefox */
-moz-transform: rotate(360deg) ;
/* WebKit */
-webkit-transform: rotate(360deg);
/* Opera */
-o-transform: rotate(360deg) ;
/* Standard */
transform: rotate(360deg) ;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<div class="icon-style-1">
<div class="builder-element-icon glyphicon glyphicon-camera">
</div>
</div>
360 degrees rotates it back to its original place. you probably wanted it to be 180deg;
if you want it animatad, you need to add a transition:
.icon-style-1 .builder-element-icon{
height: 100px;
width: 100px;
line-height: 100px;
background: blue;
line-height: 100px;
text-align: center;
margin: 0 auto;
display: block;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
color: white;
-moz-transition: -moz-transform ease 0.6s;
-webkit-transition: -webkit-transform ease 0.6s;
-o-transition: -o-transform ease 0.6s;
-ms-transition: -ms-transform ease 0.6s;
transition: transform ease 0.6s;
}
.icon-style-1 .builder-element-icon:hover{
background: green;
-moz-transform: rotate(360deg);
-webkit-transform: rotate(360deg);
-o-transform: rotate(360deg);
-ms-transform: rotate(360deg);
transform: rotate(360deg);
}
<div class="icon-style-1">
<span class="builder-element-icon fa fa-camera">a</span>
</div>
and in case you want to animate the background color to, you could replace transition: transform ease 0.6s; withe either
transition: transform ease 0.6s, background ease 0.6s;
or
transition: all ease 0.6s;
You can use CSS3 transitions in order to achieve this result.
Just move your mouse over the label.
#rotatable {
font-size: 30px;
}
#rotatable:hover {
-moz-transform: rotate(360deg);
-webkit-transform: rotate(360deg);
-o-transform: rotate(360deg);
-ms-transform: rotate(360deg);
transform: rotate(360deg);
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
<span id="rotatable">I can rotate!</span>
You forgot to add CSS Transitions. Also, you don't need to use -moz, -ms and -o vendor prefixes now, see Can I Use:
JSFiddle
.icon-style-1 .builder-element-icon {
height: 100px;
width: 100px;
line-height: 100px;
background: blue;
text-align: center;
margin: 0 auto;
display: block;
border-radius: 50%;
color: white;
-webkit-transition: all 0.5s;
transition: all 0.5s;
}
.icon-style-1 .builder-element-icon:hover {
background: green;
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="icon-style-1">
<span class="builder-element-icon fa fa-camera"></span>
</div>