Gravy
Gravy

Reputation: 12445

CSS3 Flip functionality (problems with backface-visibility)

I am following a CSS3 tutorial to offer cardflip functionality.

When the user hovers or touches the image, I wish for the image to flip over and display a 2nd image.

So far, I have:

    /* entire container, keeps perspective */
.flip-container {
    perspective: 1000;
}
    /* flip the pane when hovered */
    .flip-container:hover .flipper {
        transform: rotateY(180deg);
        -webkit-transform: rotateY(180deg);
        -moz-transform: rotateY(180deg);
        -o-transform: rotateY(180deg);
    }

.flip-container, .front, .back {
    width: 300px;
    height: 300px;
}

/* flip speed goes here */
.flipper {
    transition: 0.6s;
    transform-style: preserve-3d;
    position: relative;
}

/* hide back of pane during swap */
.front, .back {
    backface-visibility: hidden;
    -webkit-backface-visibility:hidden; /* Chrome and Safari */
    -moz-backface-visibility:hidden; /* Firefox */
    -ms-backface-visibility:hidden; /* Internet Explorer */
    position: absolute;
    top: 0;
    left: 0;
}

/* front pane, placed above back */
.front {
    z-index: 2;
}

/* back, initially hidden pane */
.back {
    transform: rotateY(180deg);
    -webkit-transform: rotateY(180deg);
    -moz-transform: rotateY(180deg);
    -o-transform: rotateY(180deg);
}

http://jsfiddle.net/jP39d/

The problem is that the front image shows the image still despite me setting backface-visibility: hidden;, but reversed. Image 2 is nowhere to be seen!

Reverse of 1st image

Upvotes: 1

Views: 1721

Answers (1)

Andy
Andy

Reputation: 4097

Add -webkit-transform-style: preserve-3d; besides transform-style: preserve-3d;. It should work now.

And I guess you want to use -webkit-perspective too because you only used perspective.

So, it's only a prefix issue. Propably you should add -moz and -o too if you want to support them.

Upvotes: 3

Related Questions