CSS rotateX around center - css

Alright. I've done quite a bit of research, but I wasn't able to come up with anything. After possibly over-thinking the problem, here is what I'd appreciate your help with.
I would like to be able to rotate a <div> around its center so its backside becomes visible. I was able to do that with rotateY--without any problems. But when using rotateX the <div> does not rotate around its center anymore.
The CSS:
.flip-container {
font-size: 30px;
-webkit-perspective: 1000;
-moz-perspective: 1000;
margin: 0 auto;
color: black;
}
.flip-container:hover .flipper {
-webkit-transform: rotateX(180deg);
-moz-transform: rotateX(180deg);
-o-transform: rotateX(180deg);
-ms-transform: rotateX(180deg);
}
.flipper {
-webkit-transition: 0.6s;
-webkit-transform-style: preserve-3d;
-moz-transition: 0.6s;
-moz-transform-style: preserve-3d;
position: relative;
}
.front, .back {
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
background: transparent;
}
.front {
z-index: 1;
}
.flip-container, .front, .back {
width: 200px;
height: 200px;
}
.back {
-webkit-transform: rotateX(-180deg);
-moz-transform: rotateX(-180deg);
-o-transform: rotateX(180deg);
-ms-transform: rotateX(180deg);
This problem is driving me up the walls. I know it's something small I overlooked; but I can't find it. Any helps or hints would be greatly appreciated. :)
Fiddle

For a vertical rotation, you need to specify transform-origin, with :
<x> : 50%
<y> : half height of the div
Updated Fiddle
.flipper {
-webkit-transform-origin: 50% 100px;
-moz-transform-origin: 50% 100px;
-o-transform-origin: 50% 100px;
-ms-transform-origin: 50% 100px;
transform-origin: 50% 100px;
-webkit-transition: 0.6s;
-webkit-transform-style: preserve-3d;
-moz-transition: 0.6s;
-moz-transform-style: preserve-3d;
position: relative;
}

Related

CSS transition and transform-style not working on mobile

I've successfully gotten two images to flip like a card when hovering over. Using transition and transform-style. It works except on mobile (iPhone; chrome and safari). What am I doing wrong? Any guidance very much appreciated.
I've reviewed previous posts on StackOverflow but what I've found did not help my situation.
<div class="flip-box">
<div class="flip-box-inner">
<div class="flip-box-front">
<img src="./resources/images/green.jpg" alt="" style="width:421px;height:552px">
</div>
<div class="flip-box-back">
<img src="./resources/images/brown.jpg" alt="" style="width:421px;height:552px">
</div>
</div>
</div>
.flip-box {
background-color: transparent;
width: 421px;
height: 552px;
border: 0px;
-webkit-perspective: 1000px;
-moz-perspective: 1000px;
-ms-perspective: 1000px;
perspective: 1000px;
}
.flip-box-inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-ms-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.flip-box:hover .flip-box-inner {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
transform: rotateY(180deg);
transform-style: preserve-3d;
}
.flip-box-front, .flip-box-back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-o-backface-visibility: hidden;
-ms-backface-visibility: hidden;
}
.flip-box-front {
transform-style: preserve-3d;
}
.flip-box-back {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
transform: rotateY(180deg);
transform-style: preserve-3d;
}
I expected the card to flip back and forth on mobile but it only transitions once.
Not answering the direct question, but maybe try the CSS from DavidWalsh.name (with prefixes).
/* entire container, keeps perspective */
.flip-box {
-webkit-perspective: 1000px;
perspective: 1000px;
}
/* flip the pane when hovered */
.flip-box-inner:hover .flipper, .flip-box-inner.hover .flipper {
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.flip-box, .flip-box-front, .flip-box-back {
width: 421px;
height: 552px;
}
/* flip speed goes here */
.flip-box-inner {
-webkit-transition: 0.6s;
transition: 0.6s;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
position: relative;
}
/* hide back of pane during swap */
.flip-box-front, .flip-box-back {
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
}
/* front pane, placed above back */
.flip-box-front {
z-index: 2;
/* for firefox 31 */
-webkit-transform: rotateY(0deg);
transform: rotateY(0deg);
}
/* back, initially hidden pane */
.flip-box-back {
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}

flip animation is not working in chrome on mac OS X

I have a dashboard in that I am using CSS3 flip animations,the flip animations are working fine in windows but when comes to chrome on Mac OS X the flip animation is flickering when I am hovering on that DIV.Please provide me some fix.
Thanks.
CSS:
Here the problem is only with 'back face' when I am hovering on that div it is flickering.
#f1_container {
position: relative;
width: 100%;
z-index: 1;
margin-bottom: 20px;
display: inline-block;
}
#f1_container {
-webkit-perspective: 1000;
-moz-perspective: 1000;
-ms-perspective: 1000;
-o-perspective: 1000;
perspective: 1000;
}
#f1_card {
width: 100%;
height: 100%;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-ms-transform-style: preserve-3d;
-o-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transition: 1.5s ease-in-out;
-moz-transition: 1.5s ease-in-out;
-ms-transition: 1.5s ease-in-out;
-o-transition: 1.5s ease-in-out;
transition: 1.5s ease-in-out;
background-color: white;
}
#f1_container:hover #f1_card {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.face {
position: relative;
width: 100%;
height: 100%;
-moz-transform-style: preserve-3d;
-moz-backface-visibility: hidden;
-webkit-transform-style: preserve-3d;
-webkit-backface-visibility: hidden;
top: 0;
}
.face.back {
display: block;
-webkit-transform: rotateY(-180deg);
-moz-transform: rotateY(-180deg);
-ms-transform: rotateY(-180deg);
-o-transform: rotateY(-180deg);
transform: rotateY(-180deg);
box-sizing: border-box;
color: white;
text-align: center;
position: absolute;
-moz-transform-style: preserve-3d;
-moz-backface-visibility: hidden;
-webkit-transform-style: preserve-3d;
-webkit-backface-visibility: hidden;
-moz-transform: rotateY(-180deg);
-webkit-transform: rotateY(-180deg);
}
.no-flick{
-webkit-transform:translate3d(0,0,0);
-moz-transform:translate3d(0,0,0);
-ms-transform:translate3d(0,0,0);
-o-transform:translate3d(0,0,0);
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-ms-backface-visibility: hidden;
-o-backface-visibility: hidden;
backface-visibility: hidden;
}
I experienced the same issue using Chrome 57 on OSX. Upon flipping the card, the back would show briefly and then disappear to white.
My solution was to set background-color: white; on the front and back instead of the flip container. Not 100% sure why the background color is an issue but it flips correctly now with no flicker! :)

How do I debug disappearing rotated elements in CSS?

I have a card with something on the back, and I'm y-rotating the card +/- 180 deg:
http://jsfiddle.net/s46t6cem/1/
#back {
transform: rotateY(180deg);
}
.flipped-right {
transform: rotateY(180deg);
}
.flipped-left {
transform: rotateY(-180deg);
}
In the jsfiddle basic example, both flips work fine. However, in my application, flipping right works, but when I flip left, I can see the back as it's moving (it flickers though, which is odd), but then I can't see the back when it stops moving. I can see it if I change the original #back rotation to 181 deg.
and then
I can't figure out what's different between the fiddle and my app that might be causing this. How can I further diagnose this?
I dont know how to debug this kind of things. But maybe you need to add some x-browser propierty:
-webkit -moz -o -ms. I have used this code in other project, try it, it worked for me (not for IE)
<style>
.flip-container {
position: relative;
height: 100%;
-webkit-perspective: 800;
-moz-perspective: 800;
-o-perspective: 800;
-ms-perspective: 800;
perspective: 800;
padding: 0;
}
.flip {
height: 100%;
width: 100%;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-ms-transform-style: preserve-3d;
-o-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-ms-transition: all 0.5s;
-o-transition: all 0.5s;
transition: all 0.5s;
}
.flip-container:hover .flip {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.side {
position: absolute;
height: 100%;
width: 100%;
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-o-backface-visibility: hidden;
}
.flip .front {
height: 100%;
width: 100%;
}
.flip .back {
display: block;
height: 100%;
width: 100%;
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
transform: rotateY(180deg);
}
</style>
<div class="flip-container">
<div class="flip">
<div class="side front">
a
</div>
<div class="side back">
b
</div>
</div>
</div>
Thank you #mknadler, I took background: white off of the #card and it works.

CSS3 effects doesn't work

If I try to make an only css3 flip effect and that will work in all major browsers, I fail.
anaxshipping.com/site is the url and the flipping effect is at home page at the three top icons.
-webkit-perspective: 1000;
-moz-perspective: 1000;
-ms-perspective: 1000;
perspective: 1000;
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
transform: rotateY(180deg);
I tried also the perspective with px. In chrome it works. In Mozilla it doesn't. Should I paste the rest of the code?
/* entire container, keeps perspective */
.flip-container {
-webkit-perspective: 1000px;
-moz-perspective: 1000px;
-ms-perspective: 1000px;
perspective: 1000px;
}
/* flip the pane when hovered */
.flip-container:hover .flipper, .flip-container.hover .flipper {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.flip-container, .front, .back {
// width: 100%;
// height: 21em;
width: 320px;
height: 480px;
}
/* flip speed goes here */
.flipper {
-webkit-transition:0.6s;
-moz-transition:0.6s;
-ms-transition:0.6s;
transition: 0.6s;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-ms-transform-style: preserve-3d;
transform-style: preserve-3d;
position: relative;
}
/* hide back of pane during swap */
.front, .back {
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-ms-backface-visibility: hidden;
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
}
/* front pane, placed above back */
.front {
z-index: 2;
}
/* back, initially hidden pane */
.back {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
transform: rotateY(180deg);
}
for 3D animations, use this ordering:
(for better realization i wrote it in nested form)
#world {
perspective: 1000px; //px needed
-webkit-perspective: 1000;
-moz-perspective: 1000px; //px needed
#container {
transform-style: preserve-3d;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
.elements {
transform: ... ;
-webkit-transform: ... ;
-moz-transform: ... ;
}
}
}
.flip-container, .front, .back {
-moz-transform-style: preserve-3d;
}
I have added there the preserve-3d for Mozilla and it worked.
Thank you for the feedback!

Explanation of accurate measurements css 3d cube

I have created a cube based on this example.
http://css3.bradshawenterprises.com/transforms/#cubecarousel
What I need to understand is how can I get an exact measure (for example of 200px) of the facing side?
Usually you define the cube's faces and then you apply the transformation at half of the object (50%) so the object gets shifted forward.
How would I push it back so the facing side matches 200px?
Thank you
You should post your current code.
Anyway, I guess that your current images are 200px ?
Then taking into account that (from your link):
A 3D image slider
Note that because of the way a cube works, the image
is moved out towards the screen, and is bigger than it should be. You
should move it back by half the width of an image to make sure it is
normal size.
If you translate your cube 100px (half the width) backwards, your images will be exactly 200px.
If your images are not 200px, definitely post your code
Ok, here is the fiddle: jsfiddle.net/K99GS I tried pushing it backwards, but it changes the pivot so it rotates from the wrong origin...
Ok after trying for one day... I found out my solution was a DUD.
Here is the exact cube (216px) and the code.
How do I push it back????????
Here is the relevant css code:
#controls, #transparency {
text-align:center;
}
#controls span {
padding-right:2em;
cursor:pointer;
}
#cubeCarousel {
-webkit-perspective: 800;
-moz-perspective: 800px;
-ms-perspective: 800;
perspective: 800;
-webkit-perspective-origin: 50% 100px;
-moz-perspective-origin: 50% 100px;
-ms-perspective-origin: 50% 100px;
perspective-origin: 50% 100px;
margin:100px auto 20px auto;
width:216px;
height:216px;
}
#cubeCarousel #cubeSpinner {
position: relative;
margin: 0 auto;
height: 216px;
width: 216px;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-ms-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transform-origin: 50% 108px 0;
-moz-transform-origin: 50% 108px 0;
-ms-transform-origin: 50% 108px 0;
transform-origin: 50% 108px 0;
-webkit-transition:all 1.0s ease-in-out;
-moz-transition:all 1.0s ease-in-out;
-ms-transition:all 1.0s ease-in-out;
transition:all 1.0s ease-in-out;
}
#cubeCarousel #Ycube,#cubeCarousel #Zcube {
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-ms-transform-style: preserve-3d;
transform-style: preserve-3d;
}
#cubeCarousel .face {
position: absolute;
height: 216px;
width: 216px;
padding: 0px;
background-color:rgba(0,0,0,0.5);
}
#cubeSpinner .one {
-webkit-transform: translateZ(108px);
-moz-transform: translateZ(108px);
-ms-transform: translateZ(108px);
transform: translateZ(108px);
}
#cubeSpinner .two {
-webkit-transform: rotateY(90deg) translateZ(108px);
-moz-transform: rotateY(90deg) translateZ(108px);
-ms-transform: rotateY(90deg) translateZ(108px);
transform: rotateY(90deg) translateZ(108px);
}
#cubeSpinner .three {
-webkit-transform: rotateY(180deg) translateZ(108px);
-moz-transform: rotateY(180deg) translateZ(108px);
-ms-transform: rotateY(180deg) translateZ(108px);
transform: rotateY(180deg) translateZ(108px);
}
#cubeSpinner .four {
-webkit-transform: rotateY(-90deg) translateZ(108px);
-moz-transform: rotateY(-90deg) translateZ(108px);
-ms-transform: rotateY(-90deg) translateZ(108px);
transform: rotateY(-90deg) translateZ(108px);
}
See it in action ->
http://jsfiddle.net/K99GS/5/

Resources