I have a fiddle http://jsfiddle.net/nLhgT/
I followed the instructions here http://davidwalsh.name/css-flip and http://desandro.github.io/3dtransforms/docs/card-flip.html When I flip the card, only the front side is being shown (flipped). I can't seem to get the backface to show. I've read similar questions on stackoverflow saying the backface must be rotated first. It is indeed rotated initially in my example.
HTML
<ul>
<li>
<div class="container">
<div class="card">
<div class="front">
front
</div>
<div class="back">
back
</div>
</div>
</div>
</li>
</ul>
CSS
li {
width: 300px;
height: 260px;
position: relative;
perspective: 800px;
list-style-type: none;
}
.card {
width: 100%;
height: 100%;
position: absolute;
transform-style: preserve-3d;
-webkit-transition-duration: 400ms;
transition-duration: 400ms;
}
.card div {
display: block;
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.card .front {
background: red;
}
.card .back {
background: blue;
-webkit-transform: rotateY( 180deg );
transform: rotateY(180deg);
}
.card.flip {
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}
JS
$(document.body).on('click', '.card', function() {
console.log("CLICK");
document.querySelector('.card').classList.toggle("flip");
});
The only difference in my example is that the card is within an unordered list. I intend to make a list of these cards. But I don't think that should affect things.
So the main problem is that preserve-3d isn't supported by IE. Huge bummer, but not much that can be done about it. Therefore, you should be applying the transform to each child element, not the entire card.
The best way I've found of making a card flip is as follows:
Transform each face. The front should default to 0, the back to 180. When flipped, they should be 180 and 360 respectively.
Apply a z-index to them. The visible face should have something like 10, while the hidden one has 0. This ensures that the right one is in front at all times (even in browsers that don't support transformations)
Here is my update to your Fiddle showing a working card flip.
Here you go...
Demo Fiddle
HTML:
<ul>
<li>
<div class="container" id="flip-toggle">
<div class="card">
<div class="front">front</div>
<div class="back">back</div>
</div>
</div>
</li>
</ul>
CSS:
li {
width: 300px;
height: 260px;
position: relative;
perspective: 800px;
list-style-type: none;
}
.container {
-webkit-perspective: 1000;
-moz-perspective: 1000;
perspective: 1000;
border: 1px solid #ccc;
}
#flip-toggle.flip .card {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
transform: rotateY(180deg);
filter: FlipH;
-ms-filter:"FlipH";
}
.container, .front, .back {
width: 300px;
height: 260px;
}
.card {
-webkit-transition: 0.6s;
-webkit-transform-style: preserve-3d;
-moz-transition: 0.6s;
-moz-transform-style: preserve-3d;
transition: 0.6s;
transform-style: preserve-3d;
position: relative;
width: 100%;
height: 100%;
}
.front, .back {
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
}
.front {
background: red;
z-index: 2;
}
.back {
background: blue;
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
transform: rotateY(180deg);
}
JS:
$(document.body).on('click', '.card', function () {
console.log("CLICK");
document.querySelector('#flip-toggle').classList.toggle('flip');
});
Related
So this is a bit strange. I have a blurred element (filter: blur(..), just a black box for example here) that is scaled up slightly (transform: scale(2)) in order to hide the blurred edges. Now when a preceding element animates the transform property, the blurred element shows a visual glitch (perhaps losing its scale(2), but I'm not sure) for the duration of the animation.
I see this behavior in Chrome (on Linux), but not Firefox.
I have tried adding backface-visibility: hidden and translateZ(0) to the blurred element, but these actually cause the same visual glitch just described. I am not sure why this is.
Any workarounds or insight into this issue is appreciated! Here is a minimal reproduction:
https://jsfiddle.net/malwilley/tz4fwmu2/
button {
width: 400px;
height: 60px;
transition: transform 500ms;
}
button:hover {
transform: translateY(-4px);
}
.container {
margin-top: 20px;
overflow: hidden;
height: 200px;
width: 400px;
}
.blurred {
height: 100%;
width: 100%;
overflow: hidden;
background: black;
filter: blur(10px);
transform: scale(1.2);
}
<button>Hover me</button>
<div class="container">
<div class="blurred" />
</div>
If you use transform: translateY(20px) instead of margin-top: 20px the bug will be fixed.
button {
width: 400px;
height: 60px;
transition: transform 500ms;
}
button:hover {
transform: translateY(-4px);
}
.container {
transform: translateY(20px);
overflow: hidden; /* remove overflow: hidden to see blur */
height: 200px;
width: 400px;
}
.blurred {
height: 100%;
width: 100%;
overflow: hidden;
background: black;
filter: blur(10px);
transform: scale(1.2);
}
<button>Hover me</button>
<div class="container">
<div class="blurred" />
</div>
Sometimes these glitches in Chrome appear, when you have software rendering without support by the 3D graphics processor.
As far as I understand, you can trigger 3d support by using any Z coordinate transform.
Thus appending translateZ(0) to your scaling transform in .blurred makes the glitch go away.
Old solution
button {
width: 400px;
height: 60px;
transition: transform 500ms;
}
button:hover {
transform: translateY(-4px);
}
.container {
margin-top: 20px;
overflow: hidden;
height: 200px;
width: 400px;
}
++
.blurred {
height: 100%;
width: 100%;
overflow: hidden;
background: black;
filter: blur(10px);
transform: scale(1.2) translateZ(0);
}
<button>Hover me</button>
<div class="container">
<div class="blurred" />
</div>
New solution
I changed my style a little bit
It's now
.container {
/* ... */
transform: scale(1);
}
.blurred {
transform: scale(1.2);
}
I took another trigger for 3D rendering and used it on the .container instead of the .blurred element
button {
width: 400px;
height: 60px;
transition: transform 500ms;
}
button:hover {
transform: translateY(-4px);
}
.container {
margin-top: 20px;
overflow: hidden;
height: 200px;
width: 400px;
transform: scale(1);
}
.blurred {
height: 100%;
width: 100%;
overflow: hidden;
background: black;
filter: blur(10px);
transform: scale(1.2);
}
<button>Hover me</button>
<div class="container">
<div class="blurred" />
</div>
I'm trying to make a flip circle on my jgraph js project. Everything working fine in chrome, edge, firefox. But when I try to test in Safari and chrome 73, the element does not display at all.
I'm using "backface-visibility" and "transform" in order to make the flip circle. I guess something is wrong with these CSS attribute in chrome 73 because if I remove these attributes then the element can display well (but no effect). In safari 10.1, the element can not display even when I already removed the css attribute. It only displays the element if I change the position from absolute to fixed (you can read my css code below).
.counter-card {
margin-left: 12%;
width: 100%;
height: 100%;
cursor: pointer;
-webkit-transform-style: preserve-3d;
-webkit-transform-origin: center right;
-webkit-transition:transform 1s;
transition: transform 1s;
transform-style: preserve-3d;
transform-origin: center right;
visibility:visible;
border: red 1px;
border-radius: 100%;
overflow: visible;
}
.red-color {
background: #dd4050;
}
.yellow-color {
background: #f7e85c;
}
.purple-color {
background: #823d84;
}
.green-color {
background: #3eb763;
}
.counter-card.is-flipped {
-webkit-transform:translateX(-100%) rotateY(-180deg);
-moz-transform:translateX(-100%) rotateY(-180deg);
-o-transform:translateX(-100%) rotateY(-180deg);
transform: translateX(-100%) rotateY(-180deg);
}
.card__face {
position: absolute;
width: 100%;
height: 100%;
color: white;
border-radius: 100%;
top: 0;
left:0;
overflow: visible;
-webkit-backface-visibility: hidden;
-o-backface-visibility: hidden;
-ms-backface-visibility: hidden;
-moz-backface-visibility: hidden;
backface-visibility: hidden;
}
.card__face--front {
/* background: #DD4050; */
}
.card__face--back {
-webkit-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
transform: rotateY(180deg);
}
Html:
<div class="scene scene--card" style="width:80%;height:80%;">
<div class="counter-card">
<div class="card__face card__face--front red-color"></div>
<div class="card__face card__face--back yellow-color"></div>
</div>
</div>
I have a parent div with a class of .card and it has to children div, that rotates in opposite directions when their parent is hovered over to create a flipping card. If you hover over it and wait until the transition finishes it works fine, however if you hover over it then move the mouse of before the animation finishes the div with a class of .front rotates in the opposite direction, why and is there a way to fix this? In addition if you move the mouse on and off multiple times both children start turning at different times even though they have the same trigger- why?
https://jsfiddle.net/8pktgqpu/15/
.card,.front,.back{
width: 100px;
height: 160px;
margin: 1px;
}
.card{
position: relative;
}
.front{
background-color: red;
transform: perspective(400px) rotatey(0deg);
backface-visibility: hidden;
transition: transform 1s ease-in-out 0s;
}
.back{
backface-visibility: hidden;
transform: perspective(400px) rotatey(180deg);
background-color: blue;
transition: transform 1s ease-in-out 0s;
position: absolute;
top: 0;
}
.card:hover .front{
transform: rotatey(-180deg);
}
.card:hover .back{
transform: rotatey(0deg);
}
Add a div and use perspective and transform-style: preserve-3d; to get it
below an example
.flip {
width: 300px;
height: 500px;
perspective: 1000px;
}
.flip_box {
width: 300px;
height: 500px;
position: relative;
transition: all 0.4s linear;
-webkit-transition: all 0.4s linear;
transform-style: preserve-3d;
-webkit-transform-style: preserve-3d
}
.front, .back {
position: absolute;
width: 300px;
height: 500px;
top: 0px;
left: 0px;
border: 1px solid #666;
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
}
.front {
color: red;
font-size: 16px;
}
.back {
color: blue;
font-size: 18px;
transform: rotateY(180deg);
-webkit-transform: rotateY(180deg);
}
.flip:hover .flip_box {
transform: rotateY(180deg);
-webkit-transform: rotateY(180deg);
}
<div class="flip">
<div class="flip_box">
<div class="front">
Hello
</div>
<div class="back">
Bye
</div>
</div>
</div>
Try this...
.card-container {
perspective: 1000px;
}
.card-container:hover .card, .card-container.hover .card {
transform: rotateY(180deg);
}
.card-container, .front, .back {
width: 100px;
height: 160px;
margin: 1px;
}
.card {
transition: 1s ease-in-out 0s;
transform-style: preserve-3d;
position: relative;
}
.front, .back {
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
}
.front {
z-index: 2;
transform: rotateY(0deg);
background-color: red;
}
.back {
transform: rotateY(180deg);
background-color: blue;
}
<div class="card-container">
<div class="card">
<div class="front">
front
</div>
<div class="back">
back
</div>
</div>
</div>
I'm trying to implement a flip on an image but its preserve 3d (or probably backface-visibility) is not working on ie11.
This solution didn't work for me: -webkit-transform-style: preserve-3d not working
Here is a pen for you to try stuff and also a fiddle: http://codepen.io/vandervals/pen/XbedKY?editors=110
.container {
-ms-perspective: 1500px;
perspective: 1500px;
}
.canvas {
position: relative;
width: 300px;
-ms-transform-origin: 50% 50%;
transform-origin: 50% 50% 0;
transition: transform 1s ease 0s;
-ms-transform-style: preserve-3d;
transform-style: preserve-3d;
overflow: visible;
}
.canvas img {
max-width: 100%;
backface-visibility: hidden;
position: relative;
z-index: 2;
}
input:checked + .canvas {
transform: rotateY(180deg);
}
.red {
background: red;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 1;
backface-visibility: hidden;
transform: rotateY(180deg);
}
<div class="container">
<input type="checkbox">
<div class="canvas">
<img src="http://todofondosdeamor.com/wp-content/uploads/images/48/gatitos-1__400x300.jpg">
<div class="red"></div>
</div>
</div>
<p>That checkbox over there</p>
Internet Explorer doesn't support preserve-3d in any version (probably Spartan will).
You need to change the way you have set the transforms if you want it to work (on the item directly instead of the container)
.container{
perspective: 1500px;
}
.canvas{
position: relative;
width: 300px;
transform-origin: 50% 50% 0;
transform-style: preserve-3d;
overflow: visible;
}
.canvas img{
max-width: 100%;
backface-visibility: hidden;
position: relative;
z-index: 2;
transition: transform 1s ease 0s;
}
input:checked + .canvas img {
transform: rotateY(180deg);
}
.red{
background: red;
width: 100%;
height: 100%;
position: absolute;
top:0;
left:0;
z-index: 1;
backface-visibility: hidden;
transform: rotateY(180deg);
transition: transform 1s ease 0s;
}
input:checked + .canvas .red {
transform: rotateY(360deg);
}
<div class="container">
<input type="checkbox">
<div class="canvas">
<img src="http://todofondosdeamor.com/wp-content/uploads/images/48/gatitos-1__400x300.jpg">
<div class="red"></div>
</div>
</div>
<p>That checkbox over there</p>
This question already has answers here:
Flip a 3D card with CSS
(2 answers)
Closed 6 years ago.
I have created a css3 animation, which animate on hover. But the horizontal flip is not working correctly when i hover it keeps moving around and doest seem to repond correctly on hover either. How can i fix this?
It doest work on chrome for me and on firefox when it switched to 8 it moves
JSFiddele
<style type="Text/css">
.container {
width: 200px;
height: 260px;
position: relative;
margin: 0 auto 10px;
border: 1px solid #CCC;
-webkit-perspective: 800px;
-moz-perspective: 800px;
-o-perspective: 800px;
perspective: 800px;
}
#card {
width: 100%;
height: 100%;
position: absolute;
-webkit-transition: -webkit-transform 1s;
-moz-transition: -moz-transform 1s;
-o-transition: -o-transform 1s;
transition: transform 1s;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-o-transform-style: preserve-3d;
transform-style: preserve-3d;
}
#card.flipped {
-webkit-transform: rotateY( 180deg );
-moz-transform: rotateY( 180deg );
-o-transform: rotateY( 180deg );
transform: rotateY( 180deg );
}
#card figure {
display: block;
height: 100%;
width: 100%;
line-height: 260px;
color: white;
text-align: center;
font-weight: bold;
font-size: 140px;
position: absolute;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-o-backface-visibility: hidden;
backface-visibility: hidden;
}
#card .front {
background: red;
}
#card .back {
background: blue;
-webkit-transform: rotateY( 180deg );
-moz-transform: rotateY( 180deg );
-o-transform: rotateY( 180deg );
transform: rotateY( 180deg );
}
#card:hover {
transform:rotateY(180deg);
}
</style>
HTML
<body>
<section class="container">
<div id="card">
<figure class="front">7</figure>
<figure class="back">8</figure>
</div>
</section>
</body>
This solution is taken from the blog of David Walsh i hope it can you help you
Check this Fiddle
Blog page
<div class="flip-container">
<div class="flipper">
<div class="front">
front
</div>
<div class="back">
back
</div>
</div>
</div>
If this solution does not suit your needs, i apologize for making you lose time.
You need to add margin: 0 to your #card
Here's a working JSFiddle
please replace this .container class with
.container {
width: 200px;
height: 260px;
position: relative;
margin: 0 auto 10px;
border: 1px solid #CCC;
}
I think after do that this will work fine, no need to add "perspective" property.