CSS transform start position differs in Chrome and Safari - css

I'm working on a website for cookies. I created a keyframe to rotate the cookies and adjust the postioning. On google chrome, everything looks as expected, but in Safari the #main-cookie starts in the wrong position (somewhere in the middle of the screen), but ends in the correct position - it snaps into place at the end of the rotating. I am not sure if I am missing something but am open to suggestions to fix this issue.
Here is the CSS for the key frames in variables:
#keyframes rotate-cookie-desktop {
from {
transform-origin: 50% 50%;
-webkit-transform: translate(-50%, -5%) rotate(0deg); /* Chrome, Safari, Opera */
-moz-transform: translate(-50%, -5%) rotate(0deg);
-ms-transform: translate(-50%, -5%) rotate(0deg);
-o-transform: translate(-50%, -5%) rotate(0deg);
transform: translate(-50%, -5%) rotate(0deg); /* Standard syntax */
overflow: hidden;
}
to {
transform-origin: 50% 50%;
-webkit-transform: translate(-50%, -5%) rotate(360deg); /* Chrome, Safari, Opera */
-moz-transform: translate(-50%, -5%) rotate(360deg);
-ms-transform: translate(-50%, -5%) rotate(360deg);
-o-transform: translate(-50%, -5%) rotate(360deg);
transform: translate(-50%, -5%) rotate(360deg); /* Standard syntax */
overflow: hidden;
}
}
#media only screen and (max-width: 480px) {
html {
width: 100%;
}
#keyframes rotate-cookie-mobile {
from {
transform-origin: 50% 50%;
-webkit-transform: translate(-82%,-12%) rotate(0deg); /* Chrome, Safari, Opera */
-moz-transform: translate(-82%,-12%) rotate(0deg);
-ms-transform: translate(-82%,-12%) rotate(0deg);
-o-transform: translate(-82%,-12%) rotate(0deg);
transform: translate(-82%,-12%) rotate(0deg); /* Standard syntax */
overflow: hidden;
}
to {
transform-origin: 50% 50%;
-webkit-transform: translate(-82%,-12%) rotate(360deg); /* Chrome, Safari, Opera */
-moz-transform: translate(-82%,-12%) rotate(360deg);
-ms-transform: translate(-82%,-12%) rotate(360deg);
-o-transform: translate(-82%,-12%) rotate(360deg);
transform: translate(-82%,-12%) rotate(360deg); /* Standard syntax */
overflow: hidden;
}
}
}
Here is the relevant CSS calling the keyframe on #main-cookie:
.overlay {
background-color: var(--clr-modal-backdrop);
z-index: var(--zindex-modal-backdrop);
position: fixed;
width: 100%;
height: 100%;
overflow: hidden;
}
.offClick {
position: fixed;
width: 100%;
height: 100%;
}
.modalContainer {
display: block;
top: 5%;
left: 5%;
position: fixed;
width: 90%;
height: 90%;
background-color: var(--clr-off-white);
z-index: var(--zindex-modal);
overflow: hidden;
border-radius: 12px;
& #main-cookie {
display: flex;
z-index: var(--zindex-popover);
overflow: hidden;
position: absolute;
height: 100vh;
transform: translate(-50%,-5%);
-webkit-transform: translate(-50%,-5%);
animation: rotate-cookie-desktop 15s;
animation-fill-mode: forwards;
}
}
#media only screen and (max-width: 480px) {
.modalContainer {
height: 90%;
& #main-cookie {
display: block;
z-index: var(--zindex-popover);
overflow: hidden;
position: absolute;
height: 100vh;
transform: translate(-82%,-12%);
-webkit-transform: translate(-82%,-12%);
animation: rotate-cookie-mobile 15s;
}
}
}
Any help is appreciated!
I have tried resetting the top and right for the browser. That showed inconsistent results. I also tried switching the order of rotate and translate in the keyframe - that showed no difference.

Related

CSS - Rotate a shape while maintaining its shape form

I'm pretty comfortable with this solution already but it still makes quite of a shapeshift as it rotates and I wanted to ask you guys if you think of a better solution.
What I want is, given is a hexagon, that starts with one axis up and then rotates to a line at the top,its not what I got but that's just a matter of arranging the rotation accordingly. Since this shape is rendered with multiple divs (found it online not my own) on top of each other that are not visible and covers the main shape so it displays as a hexagon, all the shapes have to rotate at the same time, one thing though is that hexagon-in0 has a different rotation degree than the other, I tried setting up another keyframe with an exact same animation just changing the rotation degree values but did not work, what do you think?
When I posted the code snippet here since I didn't add a background image like in my code I realize it looks like a cube rotating outside-in, kinda cool
.hexagon {
position: relative;
left: 50%;
top: 0%;
transform: translate(-50%, 0%);
cursor: pointer;
visibility: hidden;
width: 400px; /*400*/
height: 200px; /*200*/ }
.hexagon-in0 {
overflow: hidden;
width: 100%;
height: 100%;
-webkit-transform: rotate(120deg);
-moz-transform: rotate(120deg);
-ms-transform: rotate(120deg);
-o-transform: rotate(120deg);
transform: rotate(120deg); }
.hexagon-in1 {
overflow: hidden;
width: 100%;
height: 100%;
animation: rotateHex 5s ease-in 1s forwards;
-webkit-transform: rotate(-60deg);
-moz-transform: rotate(-60deg);
-ms-transform: rotate(-60deg);
-o-transform: rotate(-60deg);
transform: rotate(-60deg);}
.hexagon-in2 {
width: 100%;
height: 100%;
background-repeat: no-repeat;
background-position: 50%;
background: rgb(70,243,252);
background: radial-gradient(circle, rgba(70,243,252,1) 0%, rgba(67,28,130,1) 57%);
visibility: visible;
animation: rotateHex 5s ease-in 1s forwards;
-webkit-transform: rotate(-60deg);
-moz-transform: rotate(-60deg);
-ms-transform: rotate(-60deg);
-o-transform: rotate(-60deg);
transform: rotate(-60deg);}
#keyframes rotateHex {
0%{
transform: rotate(-120deg);
}
100%{
transform: rotate(-60deg);
}
<div class="hexagon"><div class="hexagon-in0"><div class="hexagon-in1"><div class="hexagon-in2"></div></div></div></div>
Rotate the container instead of each individual piece.
.hexagon {
position: relative;
left: 50%;
top: 0%;
transform: translate(-50%, 0%);
cursor: pointer;
visibility: hidden;
width: 400px; /*400*/
height: 200px; /*200*/
animation: rotateHex 5s ease-in 1s forwards;
}
.hexagon-in0 {
overflow: hidden;
width: 100%;
height: 100%;
-webkit-transform: rotate(120deg);
-moz-transform: rotate(120deg);
-ms-transform: rotate(120deg);
-o-transform: rotate(120deg);
transform: rotate(120deg);
}
.hexagon-in1 {
overflow: hidden;
width: 100%;
height: 100%;
-webkit-transform: rotate(-60deg);
-moz-transform: rotate(-60deg);
-ms-transform: rotate(-60deg);
-o-transform: rotate(-60deg);
transform: rotate(-60deg);
}
.hexagon-in2 {
width: 100%;
height: 100%;
background-repeat: no-repeat;
background-position: 50%;
background: rgb(70,243,252);
background: radial-gradient(circle, rgba(70,243,252,1) 0%, rgba(67,28,130,1) 57%);
visibility: visible;
-webkit-transform: rotate(-60deg);
-moz-transform: rotate(-60deg);
-ms-transform: rotate(-60deg);
-o-transform: rotate(-60deg);
transform: rotate(-60deg);}
#keyframes rotateHex {
0%{
transform: translate(-50%, 0%) rotate(-120deg);
}
100%{
transform: translate(-50%, 0%) rotate(-60deg);
}
<div class="hexagon"><div class="hexagon-in0"><div class="hexagon-in1"><div class="hexagon-in2"></div></div></div></div>

Half or 1/4 spin and return two circles

I have never done animations in CSS, what I'm trying to get is something like cog's animations two circles spinning, one to the right and the other to the left without overlapping...
I think I got the animation(sort of) but not the drawing I think..
I have this demo: https://jsfiddle.net/Tankers/8dxh94zp/9/
the "figures" are correct and the location also correct but the animation is not.
when they spin it overlaps may be is because the object are not 100% squares?, what need to be visible is just half circles just the way that is in my demo..
HTML
<div class="wrap">
<div class="top"></div>
<div class="bott"></div>
</div>
CSS
#keyframes half_spin {
0% {
-ms-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
40% {
-ms-transform: rotate(20deg);
-moz-transform: rotate(20deg);
-webkit-transform: rotate(20deg);
-o-transform: rotate(20deg);
transform: rotate(20deg);
}
60% {
-ms-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
80% {
-ms-transform: rotate(-20deg);
-moz-transform: rotate(-20deg);
-webkit-transform: rotate(-20deg);
-o-transform: rotate(-20deg);
transform: rotate(-20deg);
}
100% {
-ms-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
}
.wrap {
display: block;
overflow: hidden;
position: relative
}
.top {
width: 300px;
height: 150px;
border: 1px solid red;
border-bottom-left-radius: 151px;
border-bottom-right-radius: 151px;
position: relative;
animation: half_spin 5000ms ease-in-out infinite;
}
.top:before {
position: absolute;
width: 100%;
height: 1px;
background: red;
content: " ";
top: 0;
left: 0;
}
.bott {
width: 300px;
height: 150px;
border: 1px solid black;
border-top-left-radius: 151px;
border-top-right-radius: 151px;
animation: half_spin 5000ms ease-in-out infinite reverse;
position: relative;
}
.bott:before {
position: absolute;
width: 100%;
height: 1px;
background: black;
content: " ";
bottom: 0;
left :0;
}
If I understand your question correctly, this code snippet is what you're looking for. I added a transform-origin property to both the top and bottom half-circles to specify the point that we're rotating around.
Both divs should rotate around the midpoint of their flat edge, for the top that is transform-origin: 50% 0%; and for the bottom it is transform-origin: 50% 100%;
#keyframes half_spin {
0% {
-ms-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
40% {
-ms-transform: rotate(20deg);
-moz-transform: rotate(20deg);
-webkit-transform: rotate(20deg);
-o-transform: rotate(20deg);
transform: rotate(20deg);
}
60% {
-ms-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
80% {
-ms-transform: rotate(-20deg);
-moz-transform: rotate(-20deg);
-webkit-transform: rotate(-20deg);
-o-transform: rotate(-20deg);
transform: rotate(-20deg);
}
100% {
-ms-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
}
.wrap {
display: block;
overflow: hidden;
position: relative
}
.top {
width: 300px;
height: 150px;
border: 1px solid red;
border-bottom-left-radius: 151px;
border-bottom-right-radius: 151px;
position: relative;
animation: half_spin 5000ms ease-in-out infinite;
transform-origin: 50% 0%;
}
.top:before {
position: absolute;
width: 100%;
height: 1px;
background: red;
content: " ";
top: 0;
left: 0;
}
.bott {
width: 300px;
height: 150px;
border: 1px solid black;
border-top-left-radius: 151px;
border-top-right-radius: 151px;
animation: half_spin 5000ms ease-in-out infinite;
position: relative;
transform-origin: 50% 100%;
}
.bott:before {
position: absolute;
width: 100%;
height: 1px;
background: black;
content: " ";
bottom: 0;
left :0;
}
<div class="wrap">
<div class="top">
</div>
<div class="bott">
</div>
</div>

pseudoelement disappears on chrome mobile and works fine on desktop

I am making a connect4 game that works fine on desktop but on chrome mobile the pseudoelements doesn't appear which is the circles in the game.
.circle::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 50%;
transform: translateY(-100%);
-webkit-transform: translateY(-100%);
-moz-transform: translateY(-100%);
}
:is(.circle.red, .circle.blue)::before {
transition: 0.3s transform ease-in;
transform: translateY(0);
-webkit-transform: translateY(0);
-moz-transform: translateY(0);
}
.circle.red::before {
background: #ff0000;
}
.circle.blue::before {
background: #0000ff;
}
Where is the problem ?
The problem was in :is operator is not supported in chrome mobile

CSS rotate transform makes image blurry

I created an octagon clipped style using CSS transform rotate and scale as the code snippet below.
However, when looking in Chrome 52.0.2743.116 (64-bit) on El Capitan, the image looks blurry. On the contrary, the image looks sharp in Firefox.
I have tried all kinds of solutions such as backface-visibility: hidden; transform: translateZ(0); filter: blur(0); image-rendering: -webkit-optimize-contrast;. Yet the image is still blurry.
Is there any webkit specific rules that I can use to fix this?
div.octagon {
display: inline-block;
position: relative;
overflow: hidden;
-webkit-transform: rotate(22.5deg) scale(0.9) translateY(-4px) translateZ(0);
-moz-transform: rotate(22.5deg) scale(0.9) translateY(-4px) translateZ(0);
-ms-transform: rotate(22.5deg) scale(0.9) translateY(-4px) translateZ(0);
-o-transform: rotate(22.5deg) scale(0.9) translateY(-4px) translateZ(0);
transform: rotate(22.5deg) scale(0.9) translateY(-4px) translateZ(0);
margin-top: 1em;
margin-bottom: 1em;
}
div.octagon > * {
position: relative;
overflow: hidden;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
background: transparent;
border: 4px solid;
margin: 0;
background-color: black;
}
div.octagon > *:after {
position: absolute;
/* There needs to be a negative value here to cancel
* out the width of the border. It's currently -3px,
* but if the border were 5px, then it'd be -5px.
*/
top: -4px;
right: -4px;
bottom: -4px;
left: -4px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
content: '';
border: inherit;
}
div.octagon > * > img {
display: block;
-webkit-transform: rotate(-67.5deg) scale(1.1) translateZ(0);
-moz-transform: rotate(-67.5deg) scale(1.1) translateZ(0);
-ms-transform: rotate(-67.5deg) scale(1.1) translateZ(0);
-o-transform: rotate(-67.5deg) scale(1.1) translateZ(0);
transform: rotate(-67.5deg) scale(1.1) translateZ(0);
max-width: 100%;
height: auto;
image-rendering: -webkit-optimize-contrast;
}
.col-6 {
display: inline-block;
width: 49%;
}
.col-6 > .octagon {
width: 100%;
}
<div class="col-6">
<div class="octagon">
<p>
<img src="https://placeimg.com/300/300/people" width="500" height="500" />
</p>
</div>
</div>
<div class="col-6">
<img src="https://placeimg.com/300/300/people" width="300" height="300" />
</div>
I just tested this on my comp, and it looks better when I applied image rendering pixelated instead the -webkit-optimize-contrast.
div.octagon > * > img {
image-rendering: pixelated;
}

rotate background image from rotated div

I have added a background image to a div, but because the div has been rotated, so has the background-image. How can I rotate just the image the opposite way to it appears straight?
live url: http://bit.ly/1iqXQRN
html
<section id="about-hero-img"></section>
css
#about-hero-img {
-webkit-transform: rotate(-2deg);
-moz-transform: rotate(-2deg);
-o-transform: rotate(-2deg);
-ms-transform: rotate(-2deg);
transform: rotate(-2deg);
width: 1030px; margin-left: -50px; margin-top: 20px; height: 200px; background-image: url('../Images/about-header-img.jpg'); padding-top: 30px; }
Move the background-image to a the :before pseudo-element of you header
#about-hero-img {
-webkit-transform: rotate(-2deg);
-moz-transform: rotate(-2deg);
-o-transform: rotate(-2deg);
-ms-transform: rotate(-2deg);
transform: rotate(-2deg);
width: 1030px;
margin-left: -50px;
margin-top: 20px;
height: 200px;
/* background-image: url('../Images/about-header-img.jpg'); */
padding-top: 30px;
position: relative;
}
#about-hero-img:before {
width: 1030px;
height: 230px;
position: absolute;
left: 0;
top: 0;
content: ' ';
background-image: url('../Images/about-header-img.jpg');
-webkit-transform: rotate(2deg);
-moz-transform: rotate(2deg);
-o-transform: rotate(2deg);
-ms-transform: rotate(2deg);
transform: rotate(2deg);
}

Resources