Enlarging Images on Flip Cards - html

I have been learning about flip cards and I have run into an issue. I have two cards that when they are flipped, there is a picture on the back. By moving the mouse a second time, the picture should enlarge. The issue I am having is when the image on the card to the left is enlarged, it is hidden behind the second card to the right. However, when the image on the card to the right is enlarged, it appears in front the first card. What I would like is for the picture to appear in front regardless as to what card is flipped. I have read that this is an issue with the z-index but I have been unsuccessful in figuring out where and how to set it.
The code for the web page is:
<div class = "center">
<div class="flip3d">
<div class="back"> <img class="exampleGif enlargeRight" src="https://images.pexels.com/photos/45170/kittens-cat-cat-puppy-rush-45170.jpeg?auto=compress&cs=tinysrgb&h=350"></div>
<div class="front" style="width:400% height:300%">
<p>Cats</p>
</div>
</div>
<div class="flip3d">
<div class="back"> <img class = "exampleGif enlargeLeft" src="https://images.pexels.com/photos/66898/elephant-cub-tsavo-kenya-66898.jpeg?auto=compress&cs=tinysrgb&h=350"></div>
<div class="front" style="width:400% height:300%">
<p>Elephant</p>
</div>
</div>
The css file is:
.flip3d{
width:400px;
height:300px;
margin: 10px;
float: left;
}
.flip3d > .front{
position: absolute;
transform: perspective(600px) rotateY(0deg);
width:400px;
height:300px;
border-radius: 7px;
background: #267326; /* was #FCO */
backface-visibility: hidden;
transition: transform .5s linear 0s;
font-size:1.5vw;
font-family: Arial, Helvetica, sans-serif;
font-style: oblique;
color: white;
text-align: center;
}
.flip3d > .back{
position: absolute;
transform: perspective(600px) rotateY(180deg);
width:400px;
height:300px;
border-radius: 7px;
background: #80BFFF;
backface-visibility: hidden;
transition: transform .5s linear 0s;
}
.flip3d:hover > .front{
transform: perspective(600px) rotateY(-180deg);
}
.flip3d:hover > .back{
transform: perspective(600px) rotateY(0deg);
}
img.exampleGif {
width:400px;
height:300px;
z-index:0;
position:relative;
}
.center {
margin: auto;
width: 50%;
border: none;
padding: 10px;
}
.enlargeRight:hover {
transform:scale(2,2);
transform-origin:0 0;
transition: all .5s;
}
.enlargeLeft:hover {
transform:scale(2,2);
transform-origin:right top;
transition: all .5s;
}
The code that I am using is located here.
Than you for your help.

Add z-index in the class below with the same value as I did. There is little doc to increase your knowledge.
EDIT: This doesn't need the value to equal 1 or 2. Just z-index in .back must be greater than in .front.
.flip3d > .back{
position: absolute;
transform: perspective(600px) rotateY(180deg);
width:400px;
height:300px;
border-radius: 7px;
background: #80BFFF;
backface-visibility: hidden;
transition: transform .5s linear 0s;
z-index: 1;
}

Related

CSS Animation: `backface-visibility` causing cross-browser problems?

I'm developing a flip animation to show new numbers; it's much like an analog clock or calendar with the hinge in the middle.
The approach is straight forward: have a div with:
The bottom half of the first number on one side
The top half of the second number rotated 180 degrees so it's on the back
In order to show the new number, I rotate that whole div around the center of the container, revealing the back of the rotating div:
Number flip animation in latest Firefox
However, in Chrome, the animation doesn't always work. Sometimes half disappears completely until the transition animation is complete and sometimes the old number doesn't render: Number flip animation in latest Chrome with the bottom of the number not appearing till after animation is complete
In Safari 12, it's worse, it doesn't seem to respect backface-visibility, even with the -webkit- prefix:
Safari 12 Number animation, the bottom half of the first number is inverted after animation is complete
Pre-Chromium Edge handles this fine, but new (checked in v83) Edge has the same issue as Chrome.
I've tried messing around with the properties and have looked through other backface-visibility questions here.
Here's the code, hover over the numbers to see the flip:
body {
background: #2e517d;
}
.container {
width: 175px;
height: 192px;
background: #4e9bfa;
position: relative;
left: 50%;
transform: translate(-50%, 50%);
perspective: 1000px;
}
.cover {
width: 175px;
height: 50%;
position: absolute;
top: 96px;
background-color: #34b58c;
transform: rotateX(0deg);
transform-style: preserve-3d;
transform-origin: top;
transition: all 0.5s ease-out;
}
.container:hover .cover {
transform: rotateX(180deg);
}
.flip {
margin: 0;
display: block;
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
.container p {
font-size: 1000%;
margin: 0;
}
.container>p {
height: 96px;
overflow: hidden;
}
.front-number-bottom {
position: relative;
height: 96px;
overflow: hidden;
background-color: red;
}
.front-number-bottom p {
margin: 0;
position: relative;
top: -96px;
}
.back-number-top {
position: relative;
height: 96px;
overflow: hidden;
}
.back-number-bottom {
height: 96px;
overflow: hidden;
position: relative;
z-index: -1;
}
.back-number-bottom p {
margin: 0;
position: relative;
top: -96px;
}
div.front {
background: red;
}
div.back {
background: green;
transform: rotateX(180deg);
}
<body>
<div class="container">
<p>76</p>
<div id="cover" class="cover">
<div class="flip front">
<div class="front-number-bottom">
<p>76</p>
</div>
</div>
<div class="flip back">
<div class="back-number-top">
<p>77</p>
</div>
</div>
</div>
<div class="back-number-bottom">
<p>77</p>
</div>
</div>
</div>
</body>
Is this a sound approach that can be easily fixed in Chromium browsers and Safari?
Would a different approach be better?
I guess your code is a bit complex. I would simplify your logic like below where you no more need backface-visibility: hidden;
Note the usage of two important things:
the mask that allow me to cut the element and show only 50% of the height (top or bottom). This will make the animation more realistic since each number will have both top and bottom part seperated.
the z-index trick where I apply a transtion that change the z-index exactly at the middle of the animation (when the rotations are at 90deg)1.
.card {
width: 175px;
height: 192px;
position: relative;
z-index:0;
left: 50%;
transform: translate(-50%, 50%);
font-size: 160px;
}
.card span,
.card span::before,
.card span::after {
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
}
.card span {
position:absolute;
z-index:2;
perspective: 1000px;
}
.card span:first-child {
z-index:3;
transition:0s 0.25s all linear;
}
.card span::before,
.card span::after{
content:attr(data-number);
-webkit-mask:linear-gradient(#fff,#fff) top/100% 50% no-repeat;
mask:linear-gradient(#fff,#fff) top/100% 50% no-repeat;
background:red;
transition:0.5s all linear;
transform-style: preserve-3d;
}
.card span::after {
-webkit-mask-position:bottom;
mask-position:bottom;
background:green;
}
.card span:first-child::after {
transform: rotateX(0deg);
}
.card span:last-child::before {
transform: rotateX(-180deg);
}
/* Hover */
.card:hover span:first-child {
z-index:1;
}
.card:hover span:first-child::after {
transform: rotateX(180deg);
}
.card:hover span:last-child::before {
transform: rotateX(0deg);
}
<div class="card">
<span data-number="76"></span>
<span data-number="77"></span>
</div>
The mask can be replaced with clip-path too:
.card {
width: 175px;
height: 192px;
position: relative;
z-index:0;
left: 50%;
transform: translate(-50%, 50%);
font-size: 160px;
}
.card span,
.card span::before,
.card span::after {
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
}
.card span {
z-index:2;
perspective: 1000px;
}
.card span:first-child {
z-index:3;
transition:0s 0.25s all linear;
}
.card span::before,
.card span::after{
content:attr(data-number);
clip-path:polygon(0 0,100% 0,100% 50%,0 50%);
background:red;
transition:0.5s all linear;
transform-style: preserve-3d;
}
.card span::after {
clip-path:polygon(0 50%,100% 50%,100% 100%,0 100%);
background:green;
}
.card span:first-child::after {
transform: rotateX(0deg);
}
.card span:last-child::before {
transform: rotateX(-180deg);
}
/* Hover */
.card:hover span:first-child {
z-index:1;
}
.card:hover span:first-child::after {
transform: rotateX(180deg);
}
.card:hover span:last-child::before {
transform: rotateX(0deg);
}
<div class="card">
<span data-number="76"></span>
<span data-number="77"></span>
</div>
Another optimization using counter and without setting an explicit width/height
.card {
margin:0 5px;
font-family:monospace;
display:inline-block;
text-align:center;
position: relative;
z-index:0;
font-size: 150px;
counter-reset:num calc(var(--n,1) - 1);
}
/* this will defined the height/width*/
.card::after {
content:counter(num);
visibility:hidden;
}
/**/
.card span,
.card span::before,
.card span::after {
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
}
.card span {
z-index:2;
perspective: 1000px;
counter-increment:num;
}
.card span:first-child {
z-index:3;
transition:0s 0.25s all linear;
}
.card span::before,
.card span::after{
content:counter(num);
clip-path:polygon(0 0,100% 0,100% 50%,0 50%);
background:red;
transition:0.5s all linear;
transform-style: preserve-3d;
}
.card span::after {
clip-path:polygon(0 50%,100% 50%,100% 100%,0 100%);
background:green;
}
.card span:first-child::after,
.card:hover span:last-child::before{
transform: rotateX(0deg);
}
.card span:last-child::before {
transform: rotateX(-180deg);
}
.card:hover span:first-child::after {
transform: rotateX(180deg);
}
.card:hover span:first-child {
z-index:1;
}
<div class="card" style="--n:75">
<span></span><span></span>
</div>
<div class="card" style="--n:5">
<span></span><span></span>
</div>
<div class="card" style="--n:100">
<span></span><span></span>
</div>
1 When using linear it's pretty easy but it's more trick with other ease functions. Here is a related question that can help you identify the middfle of ease functions: When exactly does an ease animation reach its midpoint?

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>

z-index issue on hover effect using transform rotate and scale

I have what i believe to be a z-index issue with my rotate and scale hover effect.
Fiddle here
when hovering over the image it flips and scales up and shows the back side of the image with details etc.
The trouble is the images are all in rows and the margin between them is quite small. so when they scale they need to overlap on top of the images either side. at the moment this overlapping is fine to the left and to the top but overlapping is underneath on the images to the right and below.. really strange!
Here is my code - Html
<div id="games-container">
<div class="flip-container game">
<div class="flipper">
<a href="#">
<div class="front">
<h1>Front</h1>
</div>
<div class="back">
<span class="game-title">
<h3>BACK</h3>
<span class="mob-icon"></span>
</span>
<button class="button green">Play Now</button>
<button class="blue button">More Info</button>
</div>
</a>
</div>
</div>
<div class="flip-container game">
<div class="flipper">
<a href="#">
<div class="front">
<h1>Front</h1>
</div>
<div class="back">
<span class="game-title">
<h3>BACK</h3>
<span class="mob-icon"></span>
</span>
<button class="button green">Play Now</button>
<button class="blue button">More Info</button>
</div>
</a>
</div>
</div>
<div class="flip-container game">
<div class="flipper">
<a href="#">
<div class="front">
<h1>Front</h1>
</div>
<div class="back">
<span class="game-title">
<h3>BACK</h3>
<span class="mob-icon"></span>
</span>
<button class="button green">Play Now</button>
<button class="blue button">More Info</button>
</div>
</a>
</div>
</div>
CSS -
/* make things pretty */
#games-container{
width:800px;
margin:0 auto;
}
#games-container div.game{
margin: 0 8px 15px;
float: left;
position: relative;
z-index: 1;
}
#main-container div.inner-container div.game .front img, #main-container div.inner-container div.game .back img{
width:185px;
height: 145px;
}
span.game-title {
background-color:rgba(25,25,25,0.6);
display: block;
position: absolute;
width: 100%;
top: 0px;
margin-bottom: 25px;
text-align: center;
z-index: 1;
}
span.game-title h3 {
padding: 5px;
}
.game h3, .game:hover span.game-title{
color:silver;
transition:all 0.2s ease-in;
-webkit-transition:all 0.2s ease-in;
}
.game:hover h3, .game:hover span.game-title{
color:#fff;
background-color: #0c0c0c;
}
.game a{
display: block;
}
.back > .button{
position: relative;
z-index: 1;
}
.button{
display: block;
padding: 5px 10px;
margin:5px auto;
width:70%;
clear: both;
color:#fff;
}
button a{
text-decoration: none;
color:#e5e5e5;
display: block;
transition: ease-in 0.12s;
}
button.green:hover{
background-color: #00B200;
}
button:hover a{
color:#fff;
transform:scale(1.1);
}
.back > .button.green{
margin-top: 45px;
}
button{
color:#000;
border:none;
}
button.green{
background-color: #419907;
transition:background-color 0.4s ease-in;
-webkit-transition:background-color 0.4s ease-in;
}
button.blue{
background-color:#063e9b;
transition:background-color 0.4s ease-in;
-webkit-transition:background-color 0.4s ease-in
}
/* end of making things pretty*/
/* do some flipping */
.flip-container {
perspective: 900px
transform-style: preserve-3d;
}
.flip-container:hover .back {
transform: rotateY(0deg) scale(1.3);
z-index:4;
}
.flip-container:hover .front {
transform: rotateY(180deg);
}
.flip-container, .front, .back {
width: 185px;
height: 150px;
}
/* flip speed goes here */
.flipper {
transition: 0.9s;
transform-style: preserve-3d;
position: relative;
}
/* hide back of pane during swap */
.front, .back {
backface-visibility: hidden;
transition: 0.4s;
transform-style: preserve-3d;
position: absolute;
top: 0;
left: 0;
width: 185px;
height: 145px;
}
.front {
z-index: 2;
transform: rotateY(0deg);
background-color: #333;
color: #000;
text-align: center;
}
.back {
transform: rotateY(-180deg);
background-color: #010b15;
border: solid 2px #034baf;
}
Because you put the first z-index on this selector #games-container div.game, you can change the hover selector to this to remove the important property :
#games-container div.game:hover {
transform: scale(1.25);
-webkit-transform: scale(1.25);
-ms-transform: scale(1.25);
z-index: 2;
}
See it here
Add z-index: 2 !important; to .flip-container:hover
.flip-container:hover {
transform: scale(1.25);
-webkit-transform: scale(1.25);
-ms-transform: scale(1.25);
z-index: 2 !important;
}
Fiddle

CSS transform of div shouldn't affect content

I have outer div section and within outer div i have inner div section on mouse hover i want only outer div section should be transition and inner div section text should not transit should remain constant somebody help me out in achieving it.
Thanks!
http://jsfiddle.net/zeYZL/56/
HTML
<div class="outer">
<div class='inner'>
<p>inner text</p>
</div>
</div>
CSS
.outer
{
width:283px;
height:298px;
float:left;
background:#101820;
color:#fff;
font-family:Lato;
font-weight:900;
font-size:3.4em;
text-align:center;
line-height:298px;
transition:all 0.3s ease;
}
.outer:hover
{
-webkit-transform: scale(1.3);
-ms-transform: scale(1.3);
transform: scale(1.03);
width:283px;
height:298px;
cursor:pointer;
background-color:#ffa300;
}
when a transform is applied to the parent the child gets affected automatically and even adding transform: none to the child will have no effect. So, the best approach is to add the transform to a absolutely positioned sibling
I have used a :pseudo element :after to add a background-color and added scale to it which will prevent the child from getting scaled
.outer {
width: 283px;
height: 298px;
float: left;
color: #fff;
position: relative;
font-family: Lato;
font-weight: 900;
font-size: 3.4em;
text-align: center;
line-height: 298px;
}
.outer:after {
content: '';
background: #101820;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
transition: all 0.3s ease;
z-index: -1;
}
.outer:hover:after {
-webkit-transform: scale(1.3);
-ms-transform: scale(1.3);
transform: scale(1.03);
cursor: pointer;
background-color: #ffa300;
}
<div class="outer">
<div class='inner'>
<p>inner text</p>
</div>
</div>
Along with other css add the following for inner div.
.inner:hover {
-webkit-transition: none !important;
-moz-transition: none !important;
-o-transition: none !important;
-ms-transition: none !important;
transition: none !important;
}
You can mix it with jquery too.

css card flip internet explorer

I'm stuck on this and I've run into a brick wall, all works in Chrome, FF, Safari etc but in Internet Explorer, I get the reverse side of the front image rather than backside text, please help!!! I'm sure there's a simple answer I've overlooked but I'm on a deadline and desperatly need to get this wrapped up.
Thanks in advance for any help :)
CSS
flip-container {
perspective: 1000px;
-webkit-perspective:1000px;
}
/* flip the pane when hovered */
.flip-container:hover .flipper, .flip-container.hover .flipper {
-webkit-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
transform: rotateY(180deg);
font-family: "Montserrat Alternates regular";
text-align: center;
}
.flip-container, .front, .back {
width: 250px;
height: 250px;
font-family: "Montserrat Alternates regular";
}
/* flip speed goes here */
.flipper {
-webkit-transition: 0.6s;
-ms-transition: 0.6s;
transition: 0.6s;
-webkit-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;
-ms-backface-visibility:hidden;
backface-visibility: hidden;
margin: auto;
position: absolute;
top: 0;
left: 0;
}
/* front pane, placed above back */
.front {
z-index: 2;
border: 2px solid black;
border-radius: 30px;
-moz-border-radius: 30px;
-khtml-border-radius: 30px;
-webkit-border-radius: 30px;
-webkit-transform: rotateY(0deg);
-ms-transform: rotateY(0deg);
transform: rotateY(0deg);
width: 246px;
height: 246px;
}
/* back, initially hidden pane */
.back {
z-index:3;
background-color: #fff;
border: 2px solid black;
border-radius: 30px;
-moz-border-radius: 30px;
-khtml-border-radius: 30px;
-webkit-border-radius: 30px;
width: 246px;
height: 246px;
-webkit-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
transform: rotateY(180deg);
}
HTML:
<div class="grid-element">
<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
<div class="flipper">
<div class="front" style="background: url('images/flip2.jpg');" />
<span style="font-family: 'Montserrat Alternates regular';
font-weight:bolder; text-align: center; position: relative; top: 190px; font-size:
18pt;">Who Are We?</span> </div>
<div class="back">
<div style="text-align: center; font-family: 'Montserrat Alternates regular';
font-size: 10pt; position: relative; top: 10px;margin-left:10px; margin-right:10px;
margin-top:10px;">Founded by writers Kurt McClung and Simon Mackenzie to offer
complete story solutions for ambitious entertainment in various media: from video
games to comic books, theater and screen, novels to song writing.</div>
<img src="images/kurt.png" style="position:absolute; top:155px; left:18px; width:75px;
height:75px"/>
<img src="images/simon.png" style="position:absolute; top:155px; left:152px;
width:75px; height:75px"/>
</div>
</div>
</div>
</div>
Target site : http://www.taliespin.com
try adding -ms-perspective:1000px; as well to the following
flip-container {
perspective: 1000px;
-webkit-perspective:1000px;
}
(i'm on a mac right now, can't test in IE so its a wild guess)