Flip effect in Internet Explorer - html

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>

Related

Can't select inputs after TransformY on chrome for a "card flipping" effect

I have a "card" design in which I have an div with two children, a "front" and a "back". A "card flipping" effect is achieved by applying a rotateY(180deg) transform to the card, hiding the back-face.
I've noticed a few differences between chrome and firefox. On firefox, the animation is smooth, on chrome, there's a flash of white. But most importantly, an input element on the "back" face of the card is not clickable in Chrome.
You can see the effect in each browser in these gifs:
Any ideas on what is going on?
Code available at this pen: https://codepen.io/elbasti/pen/poJjLmP
function flipCard() {
var element = document.getElementById("flipper-container");
element.classList.toggle("flipper--flipped");
}
.flipper {
perspective: 1000px;
width: 200px;
height: 200px;
flex: 0 1 auto;
}
.card {
height: 200px;
width: 200px;
transition: transform 1s;
transform-style: preserve-3d;
padding: 0px;
backface-visibility: hidden;
}
.card__face {
box-sizing: border-box;
border-radius: 12px;
position: absolute;
height: 100%;
width: 100%;
top: 0;
left: 0;
padding: 20px;
backface-visibility: hidden;
}
.card__face--back {
background-color: #9e0495;
position: relative;
height: 100%;
color: white;
transform: rotateY(180deg);
}
.card__face--front {
background: gray;
}
.flipper.flipper--flipped .card {
transform: rotateY(180deg);
transition: transform 0.5s;
}
<div id="flipper-container" class="flipper">
<div class="card">
<div class="card__face card__face--back">
<p>I am the back</p>
<input type="text" placeholder="Back input">
<p>The back one doeesn't work in chrome :(</p>
</div>
<div class="card__face card__face--front">
<p>I am the front</p>
<input type="text" placeholder="Front input">
<p>The front input works.</p>
</div>
</div>
</div>
<button id="toggle-flip" onclick="flipCard()">Click me</button>
It seems, that .card overlaps the back after rotation.
Maybe you could rotate not .card but .card__face--front and .card__face--back. I made some modifications in snippet.
function flipCard() {
var element = document.getElementById("flipper-container");
element.classList.toggle("flipper--flipped");
}
.flipper {
perspective: 1000px;
width: 200px;
height: 200px;
flex: 0 1 auto;
}
.card {
height: 200px;
width: 200px;
transition: transform 1s;
transform-style: preserve-3d;
padding: 0px;
backface-visibility: hidden;
}
.card__face {
box-sizing: border-box;
border-radius: 12px;
position: absolute;
height: 100%;
width: 100%;
top: 0;
left: 0;
padding: 20px;
backface-visibility: hidden;
}
.card__face--back {
background-color: #9e0495;
position: absolute;
height: 100%;
color: white;
transform: rotateY(180deg);
transition: transform 0.5s;
}
.card__face--front {
background: gray;
transition: transform 0.5s;
}
.flipper.flipper--flipped .card__face--front {
transform: rotateY(-180deg);
transition: transform 0.5s;
}
.flipper.flipper--flipped .card__face--back {
transform: rotateY(0deg);
transition: transform 0.5s;
}
<div id="flipper-container" class="flipper">
<div class="card">
<div class="card__face card__face--back">
<p>I am the back</p>
<input type="text" placeholder="Back input">
<p>The back one doeesn't work in chrome :(</p>
</div>
<div class="card__face card__face--front">
<p>I am the front</p>
<input type="text" placeholder="Front input">
<p>The front input works.</p>
</div>
</div>
</div>
<button id="toggle-flip" onclick="flipCard()">Click me</button>

Showing full content of the flip card under mobile devices

I have a flip card build with css/html which is flipping on mouse hover. Everything works fine except on mobile. It is almost impossible to be flipped. The user press and hold on display until it's flipped for the back and then can't be flipped back to front.
Is it possible somehow on mobile devices just to show both sides one under another? On same screen e.g. to be disabled the flipping part and just show all the information on one page.
Here is my html and css so far
.small-text {
font-weight: 300;
}
.back .main { font-weight: 300;}
/* entire container, keeps perspective */
.card-container {
-webkit-perspective: 800px;
-moz-perspective: 800px;
-o-perspective: 800px;
perspective: 800px;
margin-bottom: 30px;
}
/* flip the pane when hovered */
.card-container:not(.manual-flip):hover .card,
.card-container.hover.manual-flip .card{
-webkit-transform: rotateY( 180deg );
-moz-transform: rotateY( 180deg );
-o-transform: rotateY( 180deg );
transform: rotateY( 180deg );
}
.card-container.static:hover .card,
.card-container.static.hover .card {
-webkit-transform: none;
-moz-transform: none;
-o-transform: none;
transform: none;
}
/* flip speed goes here */
.card {
-webkit-transition: -webkit-transform .5s;
-moz-transition: -moz-transform 1.0s;
-o-transition: -o-transform 1.0s;
transition: transform 1.0s;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-o-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;
-o-backface-visibility: hidden;
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
background-color: #FFF;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.14);
}
/* front pane, placed above back */
.front {
z-index: 2;
}
/* back, initially hidden pane */
.back {
-webkit-transform: rotateY( 180deg );
-moz-transform: rotateY( 180deg );
-o-transform: rotateY( 180deg );
transform: rotateY( 180deg );
z-index: 3;
}
/* Style */
.card{
background: none repeat scroll 0 0 #FFFFFF;
border-radius: 4px;
color: #444444;
}
.card-container, .front, .back {
width: 100%;
height: 120px;
border-radius: 4px;
}
.card .content{
background-color: rgba(0, 0, 0, 0);
box-shadow: none;
padding: 10px 20px 20px;
}
.card .content .main {
min-height: 160px;
}
.card .back .content .main {
height: 215px;
}
.card .name {
font-size: 22px;
line-height: 28px;
margin: 10px 0 0;
text-transform: capitalize;
}
.card .profession{
color:black;
margin-bottom: 20px;
font-weight: 300;
}
<div class="container main-card">
<div class="card-container">
<div class="card">
<div class="front">
<div class="content">
<div class="main">
<h3 class="name"><span style="font-size:56px;"><span style="font-family:oswald-medium,oswald,sans-serif;font-weight:900;">Header</span></span></h3>
<p class="small-text" style="font-size: 18px;width: 385px;color:#414141;">Lorem ipsum</p>
</div>
</div>
</div> <!-- end front panel -->
<div class="back">
<div class="content" style="margin-top: 20%;">
<div class="main">
<h6 style="font-size: 20px;color:#414141 !important;cursor: pointer;font-family: 'Roboto Condensed' !important;">mail#example.com</h6>
<h6 style="font-size: 20px;color:#414141;font-family: 'Roboto Condensed';">Phone 1</h6>
<h6 style="font-size: 20px;color:#414141;font-family: 'Roboto Condensed';">Phone 2</h6>
</div>
</div>
</div> <!-- end back panel -->
</div> <!-- end card -->
</div> <!-- end card-container -->
</div> <!-- end col sm 3 -->
You would need to use media queries and put the whole CSS in the media queries, and then work on each size separetly.
#media screen and (min-width: 640px) {
.small-text {
font-weight: 300;
}
.back .main {
font-weight: 300;
}
/* entire container, keeps perspective */
.card-container {
-webkit-perspective: 800px;
-moz-perspective: 800px;
-o-perspective: 800px;
perspective: 800px;
margin-bottom: 30px;
}
/* flip the pane when hovered */
.card-container:not(.manual-flip):hover .card,
.card-container.hover.manual-flip .card {
-webkit-transform: rotateY( 180deg);
-moz-transform: rotateY( 180deg);
-o-transform: rotateY( 180deg);
transform: rotateY( 180deg);
}
.card-container.static:hover .card,
.card-container.static.hover .card {
-webkit-transform: none;
-moz-transform: none;
-o-transform: none;
transform: none;
}
/* flip speed goes here */
.card {
-webkit-transition: -webkit-transform .5s;
-moz-transition: -moz-transform 1.0s;
-o-transition: -o-transform 1.0s;
transition: transform 1.0s;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-o-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;
-o-backface-visibility: hidden;
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
background-color: #FFF;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.14);
}
/* front pane, placed above back */
.front {
z-index: 2;
}
/* back, initially hidden pane */
.back {
-webkit-transform: rotateY( 180deg);
-moz-transform: rotateY( 180deg);
-o-transform: rotateY( 180deg);
transform: rotateY( 180deg);
z-index: 3;
}
/* Style */
.card {
background: none repeat scroll 0 0 #FFFFFF;
border-radius: 4px;
color: #444444;
}
.card-container,
.front,
.back {
width: 100%;
height: 120px;
border-radius: 4px;
}
.card .content {
background-color: rgba(0, 0, 0, 0);
box-shadow: none;
padding: 10px 20px 20px;
}
.card .content .main {
min-height: 160px;
}
.card .back .content .main {
height: 215px;
}
.card .name {
font-size: 22px;
line-height: 28px;
margin: 10px 0 0;
text-transform: capitalize;
}
.card .profession {
color: black;
margin-bottom: 20px;
font-weight: 300;
}
}
#media screen and (max-width: 640px) {
.small-text {
font-weight: 300;
}
.main {
font-weight: 300;
}
/* Style */
.card {
background: none repeat scroll 0 0 #FFFFFF;
border-radius: 4px;
color: #444444;
}
.card-container,
.front,
.back {
width: 100%;
height: 50px;
border-radius: 4px;
}
.card .content {
background-color: rgba(0, 0, 0, 0);
box-shadow: none;
padding: 10px 20px 20px;
}
.card .content .main {
min-height: 160px;
}
.card .back .content .main {
height: 215px;
}
.card .name {
font-size: 22px;
line-height: 28px;
margin: 10px 0 0;
text-transform: capitalize;
}
.card .profession {
color: black;
margin-bottom: 20px;
font-weight: 300;
}
}
<div class="container main-card">
<div class="card-container">
<div class="card">
<div class="front">
<div class="content">
<div class="main">
<h3 class="name"><span style="font-size:56px;"><span style="font-family:oswald-medium,oswald,sans-serif;font-weight:900;">Header</span></span>
</h3>
<p class="small-text" style="font-size: 18px;width: 385px;color:#414141;">Lorem ipsum</p>
</div>
</div>
</div>
<!-- end front panel -->
<div class="back">
<div class="content" style="margin-top: 20%;">
<div class="main">
<h6 style="font-size: 20px;color:#414141 !important;cursor: pointer;font-family: 'Roboto Condensed' !important;">mail#example.com</h6>
<h6 style="font-size: 20px;color:#414141;font-family: 'Roboto Condensed';">Phone 1</h6>
<h6 style="font-size: 20px;color:#414141;font-family: 'Roboto Condensed';">Phone 2</h6>
</div>
</div>
</div>
<!-- end back panel -->
</div>
<!-- end card -->
</div>
<!-- end card-container -->
</div>
<!-- end col sm 3 -->

How to fix text on image so that it can move with text?

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>

how to make coin flip transform in css

So, I have an icon, a circle icon, I want to make this icon when it hovered it will has coin flip transform, just like https://desandro.github.io/3dtransforms/examples/card-02-slide-flip.html but it flip two times so it goes back to the first position.
This is the HTML code:
<div class="bg">
<div class="icon">
<img src="football.png">
</div>
</div>
This is the CSS code:
.bg {
padding: 6px 6px;
float: left;
width: 20%;
}
.icon {
width: 100px;
height: 100px;
overflow: hidden;
border-radius: 50%;
box-shadow: 3px 3px 10px black;
border: 0px;
background-color: white;
margin-left: auto;
margin-right: auto;
display: block;
}
.icon img{
left: 50%;
top: 50%;
height: 100%;
width: auto;
}
.icon:hover {
transform: translateX( -1px ) rotateY( 180deg );
}
so the transform is not soft like the example from the link, and when the first flip (or rotation) I want to change the icon with different image, but when the second rotate it will back to first image. Any suggestion? thanks before
You forgot to add the animation itself, the transition.
.bg {
padding: 6px 6px;
float: left;
width: 20%;
}
.icon {
width: 100px;
height: 100px;
overflow: hidden;
border-radius: 50%;
box-shadow: 3px 3px 10px black;
border: 0px;
background-color: white;
margin-left: auto;
margin-right: auto;
display: block;
/* TRANSITION HERE!! */
-webkit-transition: transform 1s ease;
-moz-transition: transform 1s ease;
-ms-transition: transform 1s ease;
-o-transition: transform 1s ease;
transition: transform 1s ease;
/* END OF TRANSITION */
}
.icon img{
left: 50%;
top: 50%;
height: 100%;
width: auto;
}
.icon:hover {
transform: translateX( -1px ) rotateY( 180deg ); /* ALSO EXTRA TRANSFORM PROPERTIES ADDED FOR COMPATIBILITY*/
-ms-transform: translateX( -1px ) rotateY(180deg); /* IE 9 */
-webkit-transform: translateX( -1px ) rotateY(180deg); /* Chrome, Safari, Opera */
}
<div class="bg">
<div class="icon">
<img src="https://i.stack.imgur.com/RVjde.jpg">
</div>
</div>
I hope this helped.
Cheers!
You can define an animation the following:
#keyframes flip_animation {
from {transform: rotateY(0deg);}
to {transform: rotateY(360deg);}
}
And add this animation you your CSS-Class
.icon:hover {
animation-name: flip_animation;
animation-duration: 1s;
}
See this link for more information about animations in CSS.

Scaling image with CSS Transition

This is how I want to scale my images, smoothly without any jumps.
My attempt does not work like in the gallery above, the image (red square in my case) jumps, my code:
section {
background-color: rgba(0, 0, 0, 0.701961);
width: 400px;
height: 400px;
}
div {
position: absolute;
top: 120px;
left: 120px;
width: 160px;
height: 160px;
background-color: red;
-webkit-transition: all .2s ease-in-out;
}
div:hover {
-webkit-transform: scale(1.8);
}
<section>
<div></div>
</section>
How to fix this? The red square jumps. Is it possible to scale smoothly with CSS Transition at all like in the gallery in the link at the beginning?
What do you mean by "jumps"? Try this, jumps too?
section {
background-color: rgba(0, 0, 0, 0.701961);
width: 400px;
height: 400px;
}
div {
position: absolute;
top: 120px;
left: 120px;
width: 160px;
height: 160px;
background-color: red;
-webkit-transition: -webkit-transform 0.4s;
transition: transform 0.4s;
}
div:hover {
-webkit-transform: scale(1.8) rotate(0.01deg);
transform: scale(1.8) rotate(0.01deg);
}
<section>
<div></div>
</section>
Also, you could try the variant with a container for an image (like in the first link of your question).
JSFiddle
.banner {
position: relative;
z-index: 1;
cursor: pointer;
border: 1px solid #dfe2e5;
background: #000;
width: 310px;
height: 150px;
-webkit-transition: border-color 0.1s;
transition: border-color 0.1s;
overflow: hidden;
}
.banner:hover {
border-color: #bdc1c5;
}
.banner__image-container {
overflow: hidden;
height: 100%;
}
.banner__image {
-webkit-transition: all 0.4s;
transition: all 0.4s;
}
.banner:hover .banner__image {
-webkit-transform: scale(1.15) rotate(0.01deg);
transform: scale(1.15) rotate(0.01deg);
opacity: 0.5;
}
<div class="banner">
<div class="banner__image-container">
<img class="banner__image" src="https://picsum.photos/310/150/?image=1022"/>
</div>
</div>
I sometimes solve strange jumps on transition by adding rotate(0.01deg) on the transform property, like so:
.element:hover {
transform: scale(1.5) rotate(0.01deg);
}