I'm using boostrap, and I'm making a flipping animation card inside a row (col-lg-12), the problem is that when I resize the screen the card doesn't act "responsive"
.flip {
-webkit-perspective: 800;
perspective: 800;
position: relative;
text-align: center;
}
.flip .card.flipped {
-webkit-transform: rotatey(-180deg);
transform: rotatey(-180deg);
}
.flip .card {
width: 270px;
height: 178px;
-webkit-transform-style: preserve-3d;
-webkit-transition: 0.5s;
transform-style: preserve-3d;
transition: 0.5s;
}
.flip .card .face {
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
z-index: 2;
}
.flip .card .front {
position: absolute;
width: 270px;
z-index: 1;
}
.flip .card .img {
position: relaitve;
width: 270px;
height: 178px;
z-index: 1;
border: 2px solid #000;
}
.flip .card .back {
padding-top: 10%;
-webkit-transform: rotatey(-180deg);
transform: rotatey(-180deg);
}
.inner {
margin: 0px !important;
}
<div id="porosity" class="card">
<div class="face front">
<div class="inner">
<img src="http://placehold.it/100x100" class="img-responsive center-block" alt="">
<p>Porosity</p>
</div>
</div>
<div class="face back">
<div class="inner text-center">
<p>Permeable to fluids, permeable to outside influences.</p>
</div>
</div>
</div>
Full code: https://codepen.io/elunap/pen/rYJEVW
What I'm doing wrong?
If you mean that when you resize screen the flipping card stay at the left while the others stay at center, if you want to make the flipping card stay at center like the others, you have to add margin: auto as follow:
.flip .card {
/* New property added */
margin: auto
}
check the updated CodePen, hope this what you want.
Related
I have a website where users can make flash cards and use them. Iv'e tested the cards on all devices and web browsers and apple devices seem to give me problems. The animation works and allows the card to flip, but the content on the back of the card disappears. I won't include it because it's long, but I also have a JS function that adds "flipped" to the class "gallery-cell". You will see this in my CSS.
.gallery-cell.card {
position: relative;
-webkit-transition: 0.5s;
-moz-transition: 0.6s;
transition: transform .5s;
-webkit-perspective: 1000;
-moz-perspective: 1000;
-o-perspective:1000;
-ms-perspective: 1000;
perspective: 1000;
-ms-transform: perspective(1000px);
-moz-transform: perspective(1000px);
-moz-transform-style: preserve-3d;
-ms-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transform-style: preserve-3d;
word-break: break-word;
}
.card__face {
position: absolute;
height: 100%;
width: 100%;
padding: 25px;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-ms-backface-visibility: hidden;
backface-visibility: hidden;
display: flex;
justify-content: center;
text-align: center;
cursor: pointer;
}
.card__face--back {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
transform: rotateY( 180deg );
}
.card__face--front {
-moz-transform-style: preserve-3d;
-ms-transform-style: preserve-3d;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-perspective: inherit;
-moz-perspective: inherit;
-o-perspective: inherit;
-ms-perspective: inherit;
perspective: inherit;
z-index: 2;
background-color: #fff;
}
.flipped {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.card_contents {
overflow-y: auto;
margin: 0;
display: flex;
}
<div class='gallery-cell card flippable'>
<div class='card__face card__face--front'>
<div class='card_contents'>
<h3>
$question
</h3>
</div>
</div>
<div class='card__face card__face--back'>
<div class='card_contents'>
<h3>
$answer
</h3>
</div>
</div>
</div>
The reason why I reworked the CSS and HTML is b/c once adding your code to JSFiddle, it was immediately not displaying correctly.
First issue is that you need another wrapper element to hold the containers (card__face). Also perspective cannot be inherited. Unfortunately the animation would not work unless a height was supplied on the main wrapper element. min-height did not work either.
You could run some JS and determine the height on load. (see CSS3 Flip Card with Automatic Height)
<div class="gallery-cell card flippable">
<div class="wrapper">
<div class='card__face card__face--front'>
<div class='card_contents'>
<h3>
$question
</h3>
</div>
</div>
<div class='card__face card__face--back'>
<div class='card_contents'>
<h3>
$answer
</h3>
</div>
</div>
</div>
</div>
.gallery-cell {
background-color: transparent;
width: 100%;
height: 100px;
perspective: 1000px;
}
.wrapper {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.5s;
transform-style: preserve-3d;
}
.gallery-cell:hover .wrapper,
.gallery-cell.flipped .wrapper {
transform: rotateY(180deg);
}
.card__face {
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.card__face--front {
background-color: red;
}
.card__face--back {
background-color: #000;
color: white;
transform: rotateY(180deg);
}
.card_contents {
overflow-y: auto;
margin: 0;
display: flex;
}
I added the hover in case you wanted to test it - here's https://jsfiddle.net/rzqkpva9/
I've read a lot of pages talking about z-index and how transform and perspective destroys his context. I understand why my code isn't working what I don't know is how to make it work (or at least use and alternative).
As you can see on the image, the select menu is being covered by the card below.
Here is a snippet with a reproduction of the issue:
.square { position: relative; width: 100%; padding-bottom: 100%; }
.square>* { position: absolute; width: 100%; height: 100%; }
/* flip */
/* u -> uncontroled / c -> controled */
.flip { perspective: 200em; }
.flip .front, .flip .back {
-webkit-backface-visibility: hidden; -moz-backface-visibility: hidden;
backface-visibility: hidden; position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
}
#supports (-webkit-transform-style: preserve-3d) or (-moz-transform-style: preserve-3d) or (transform-style: preserve-3d) {
.flip .front, .flip .back {
-webkit-transform-style: preserve-3d; -moz-transform-style: preserve-3d; transform-style: preserve-3d; transition: 1s;
}
}
/* -> horizontal */
.flip .front { z-index: 2; transform: rotateY(0deg); perspective: none;}
.flip .back { transform: rotateY(-180deg); }
.flip.u:hover .back, .flip.c.active .back { transform: rotateY(0deg); }
.flip.u:hover .front, .flip.c.active .front { transform: rotateY(180deg); }
/* -> vertical */
.flip.vertical .back { transform: rotateX(-180deg); }
.flip.vertical.u:hover .back, .flip.vertical.c.active .back { transform: rotateX(0deg); }
.flip.vertical.u:hover .front, .flip.vertical.c.active .front { transform: rotateX(180deg); }
.test {
position: absolute; top: 70%; left: 10%; background-color: green;
height: 100px; width: 10px; z-index: 100;
}
<div style="width: 100px; background-color: black">
<div class="square flip u">
<div class="front" style="background-color: blue">
Front
<div class="test"></div>
</div>
<div class="back" style="background-color: red">Back</div>
</div>
<hr >
<div class="square flip u">
<div class="front" style="background-color: blue">Front</div>
<div class="back" style="background-color: red">Back</div>
</div>
</div>
What I need is the <div class="test"> to be displayed in front of all. Like this. But I don't want to set the z-index on the square divs, because they will be placed inside a flex layout Grid.
Is there a way to say to an element to be always rendered in front of all other? No mathers where is he placed or what is happening to the stack context.
Nobody has found a solution over this last years so here you have what I finally did (as an alternative to solve my specific problem):
I just changed the z-index of all child elements, using js, making thos childs that are first having a higher z-index.
var targets = document.getElementsByClassName("invertChildZOrder");
var i;
for (i = 0; i < targets.length; i++) {
target = targets[i];
for (var i = 0; i < target.childNodes.length; i++) {
var childNode = target.childNodes[i];
if (childNode.className == "square flip u") {
childNode.style.zIndex = "" + (target.childNodes.length - i);
}
}
}
.square { position: relative; width: 100%; padding-bottom: 100%; }
.square>* { position: absolute; width: 100%; height: 100%; }
/* flip */
/* u -> uncontroled / c -> controled */
.flip { perspective: 200em; }
.flip .front, .flip .back {
-webkit-backface-visibility: hidden; -moz-backface-visibility: hidden;
backface-visibility: hidden; position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
}
#supports (-webkit-transform-style: preserve-3d) or (-moz-transform-style: preserve-3d) or (transform-style: preserve-3d) {
.flip .front, .flip .back {
-webkit-transform-style: preserve-3d; -moz-transform-style: preserve-3d; transform-style: preserve-3d; transition: 1s;
}
}
/* -> horizontal */
.flip .front { z-index: 2; transform: rotateY(0deg); perspective: none;}
.flip .back { transform: rotateY(-180deg); }
.flip.u:hover .back, .flip.c.active .back { transform: rotateY(0deg); }
.flip.u:hover .front, .flip.c.active .front { transform: rotateY(180deg); }
/* -> vertical */
.flip.vertical .back { transform: rotateX(-180deg); }
.flip.vertical.u:hover .back, .flip.vertical.c.active .back { transform: rotateX(0deg); }
.flip.vertical.u:hover .front, .flip.vertical.c.active .front { transform: rotateX(180deg); }
.test {
position: absolute; top: 70%; left: 10%; background-color: green;
height: 100px; width: 10px; z-index: 100;
}
<div class="invertChildZOrder" style="width: 100px; background-color: black">
<div class="square flip u">
<div class="front" style="background-color: blue">
Front
<div class="test"></div>
</div>
<div class="back" style="background-color: red">Back</div>
</div>
<hr >
<div class="square flip u">
<div class="front" style="background-color: blue">Front</div>
<div class="back" style="background-color: red">Back</div>
</div>
</div>
As you can imagine. This only solves the problem partially. If the square on the botton has another menu but this times droping up instead of down we will have same problem.
I took a different approach. i removed the animation class after the animation finished. I think it is a simpler solution (and I also wasted hours trying to figure out what was going on...)
All I did was moving the div with class .test outside the div with the flipping element.
.square {
position: relative;
width: 100%;
padding-bottom: 100%;
}
.square>* {
position: absolute;
width: 100%;
height: 100%;
}
/* flip */
/* u -> uncontroled / c -> controled */
.flip {
perspective: 200em;
}
.flip .front,
.flip .back {
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
#supports (-webkit-transform-style: preserve-3d) or (-moz-transform-style: preserve-3d) or (transform-style: preserve-3d) {
.flip .front,
.flip .back {
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
transform-style: preserve-3d;
transition: 1s;
}
}
/* -> horizontal */
.flip .front {
z-index: 2;
transform: rotateY(0deg);
perspective: none;
}
.flip .back {
transform: rotateY(-180deg);
}
.flip.u:hover .back,
.flip.c.active .back {
transform: rotateY(0deg);
}
.flip.u:hover .front,
.flip.c.active .front {
transform: rotateY(180deg);
}
/* -> vertical */
.flip.vertical .back {
transform: rotateX(-180deg);
}
.flip.vertical.u:hover .back,
.flip.vertical.c.active .back {
transform: rotateX(0deg);
}
.flip.vertical.u:hover .front,
.flip.vertical.c.active .front {
transform: rotateX(180deg);
}
.test {
position: absolute;
top: 30%;
left: 3%;
background-color: green;
height: 100px;
width: 10px;
z-index: 10;
}
<div style="width: 100px; background-color: black">
<div class="square flip u">
<div class="front" style="background-color: blue">
Front
</div>
<div class="back" style="background-color: red">Back</div>
</div>
<div class="test"></div>
<hr>
<div class="square flip u">
<div class="front" style="background-color: blue">Front</div>
<div class="back" style="background-color: red">Back</div>
</div>
</div>
I try to rotate the image and enlarge it (preferably to display in the center of the screen) but it does not work.
The second problem is that when an object grows, it is under other objects (z-index does not help).
Any one can help?
.flip-container {
-webkit-perspective: 1000;
}
.flipped {
-webkit-transform: scale(2);
-webkit-transform: rotateY(180deg);
}
.flip-container,
.front,
.back {
width: 350px;
height: 230px;
}
.flipper {
-webkit-transition: 0.6s;
-webkit-transform-style: preserve-3d;
position: relative;
}
.front,
.back {
-webkit-backface-visibility: hidden;
position: absolute;
}
.front {
z-index: -1;
}
.back {
-webkit-transform: rotateY(180deg);
}
<div class="flip-container">
<div class="flipper" onclick="this.classList.toggle('flipped')">
<div class="front">
<img id="services_img" src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.svg?v=6e4af45f4d66">
</div>
<div class="back">
Wszystko za darmo
</div>
</div>
</div>
You can not set 2 transforms like this
transform: scale(2);
transform: rotateY(180deg);
As they are the same property, one will overwrite the other.
instead, concatenate the values
transform: scale(2) rotateY(180deg);
.beneath {
width: 350px;
height: 230px;
display: flex;
align-items: center;
justify-content: center;
}
.txt {
height: 25px;
}
.beneath p {
float: left;
}
.beneath img {
width: 100%;
}
.flip-container img {
width: 100%;
}
.flipped {
transform-origin: center center;
transform: rotateY(180deg) scale(2);
}
.flip-container,
.flipper,
.front,
.back {
width: 350px;
height: 230px;
position: absolute;
top: 0;
left: 0;
}
.flipper {
transition: 0.6s;
}
.front,
.back {
backface-visibility: hidden;
}
.front {
z-index: 1;
}
.back {
transform: rotateY(180deg);
}
<!-- elements beneath - example only -->
<div class="beneath txt">
<p>This is all beneath.</p>
</div>
<div class="beneath">
<img src="http://via.placeholder.com/350x150" />
</div>
<!-- Original -->
<div class="flip-container">
<div class="flipper" onclick="this.classList.toggle('flipped')">
<div class="front">
<img id="services_img" src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.svg?v=6e4af45f4d66">
</div>
<div class="back">
Wszystko za darmo
</div>
</div>
</div>
I'm lost on why it's not working for you. I've adjusted some of the code, but without extensive code, it's hard to determine what might be causing your issues.
I did notice you had a z-index of -1. I'm guessing since you said it didn't make a difference, it's a leftover from trial-and-error.
I took out relative positions, relocated your absolute position, and fixed your z-index.
From what I can tell, it's working. There may be deeper issues in your code.
.beneath {
width: 350px;
height: 230px;
display: flex;
align-items: center;
justify-content: center;
}
.txt {
height: 25px;
}
.beneath p {
float: left;
}
.beneath img {
width: 100%;
}
.flip-container img {
width: 100%;
}
.flipped {
-webkit-transform: scale(2);
-webkit-transform: rotateY(180deg);
}
.flip-container,
.front,
.back {
width: 350px;
height: 230px;
position: absolute;
top: 0;
left: 0;
}
.flipper {
-webkit-transition: 0.6s;
}
.front,
.back {
-webkit-backface-visibility: hidden;
}
.front {
z-index: 1;
}
.back {
-webkit-transform: rotateY(180deg);
}
<!-- elements beneath - example only -->
<div class="beneath txt">
<p>This is all beneath.</p>
</div>
<div class="beneath">
<img src="http://via.placeholder.com/350x150" />
</div>
<!-- Original -->
<div class="flip-container">
<div class="flipper" onclick="this.classList.toggle('flipped')">
<div class="front">
<img id="services_img" src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.svg?v=6e4af45f4d66">
</div>
<div class="back">
Wszystko za darmo
</div>
</div>
</div>
I want to fix text on image so that if my image moves or flips, my text also move or flip with the text. How can i do that ? I just want my text to be behave with the image animation.
Ex: If my image flips, Text on it should also flip.
If my image pops out , then text should also pop out
If my image moves , then text also come with it.
Overall , i just want to fix text on image.
Thanks
.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>
I have a code to make flip to a div. It's working fine in Firefox and Chrome, but in IE when the card flips, it shows the front side upside down instead of show the back side.
This is the code:
body {
background: #eee;
}
.card{
width: 300px;
height: 300px;
}
.content {
width: 300px;
height: 300px;
perspective: 500px;
box-shadow: 0 0 15px rgba(0,0,0,0.1);
transition: transform 1s;
transform-style: preserve-3d;
}
.card:hover .content {
transform: rotateX( 180deg ) ;
transition: transform 0.5s;
}
.front,
.back {
position: absolute;
height: 100%;
width: 100%;
background: white;
line-height: 300px;
color: #03446A;
text-align: center;
font-size: 60px;
border-radius: 5px;
backface-visibility: hidden;
}
.back {
background: #03446A;
color: white;
transform: rotateX( 180deg );
}
<div class="card">
<div class="content">
<div class="front">
Front
</div>
<div class="back">
Back!
</div>
</div>
</div>
As Shaggy commented, IE doesn't support preserve-3d. It also lacks support for backface-visibility: hidden;
So,you can not rotate the container, you have to rotate the elements individually.
And you need to adjust the visibility (with half the transition time, you want it to happen in the middle of the rotation.
This is the result, working ok on modern browsers and also on IE
body {
background: #eee;
}
.card{
width: 300px;
height: 300px;
}
.content {
width: 300px;
height: 300px;
perspective: 500px;
box-shadow: 0 0 15px rgba(0,0,0,0.1);
transition: transform 1s;
transform-style: preserve-3d;
}
.card:hover .content {
}
.front,
.back {
position: absolute;
height: 100%;
width: 100%;
background: white;
line-height: 300px;
color: #03446A;
text-align: center;
font-size: 60px;
border-radius: 5px;
backface-visibility: hidden;
}
.front {
transition: visibility 0.5s, transform 1s;
}
.card:hover .front {
visibility: hidden;
transform: rotateX(180deg);
}
.back {
background: #03446A;
color: white;
transform: rotateX( -180deg );
transition: visibility 0.5s, transform 1s;
}
.card:hover .back {
transform: rotateX(0deg);
}
<div class="card">
<div class="content">
<div class="front">
Front
</div>
<div class="back">
Back!
</div>
</div>
</div>