So ive been struggling with this set of code for a while now and I am so close to finishing it.
First problem was getting my images to be responsive to height and width, but after some discussions I was able to figure out how to make it responsive by simplifying the code and using colors as placeholders but now I cant figure out how to re-add the background images.
Here is the OG codepen, http://codepen.io/anon/pen/YypXjw
and here it is now, http://codepen.io/anon/pen/rOWXzW
* { color: #fff; }
.flip-container {
width: 33.333%;
padding-bottom: 33.333%;
float: left;
}
.flip-container:hover .flipper {
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.flipper {
-webkit-transition: 0.6s;
-webkit-transform-style: preserve-3d;
transition: 0.6s;
transform-style: preserve-3d;
position: relative;
}
.front {
position: absolute;
width: 100%;
padding-bottom: 100%;
}
.front-a {
background: red;
}
.front-b {
background: blue;
}
.front-c {
background: green;
}
I have no idea why I cant get the html to show up as well.
So the code was cleaned up, and now all I need to figure out is how to add a front and back image to the flipping div.
Ive attempted to add front and back divs like the og code but still cant get it to work.
Any help or suggestions is greatly appreciated.
Codepen
You need the front and back classed divs. You can target the front/back of each using pseudo selectors.
<div class="flip-container">
<div class="flipper">
<div class="front"></div>
<div class="back"></div>
</div>
</div>
Background size cover and then each front/back's image.
.front, .back {
background-size: cover;
}
.flip-container:nth-of-type(1) .front {
background-image: url(image.jpg);
}
.flip-container:nth-of-type(1) .back {
background-image: url(image.jpg);
}
Related
In many tutorial, they use backface-visibility:hidden to make a flippable card. But it(card) works fine without backface-visibility:hidden. So why they use it? Any solution.
Css:
.scene {
width: 200px;
height: 260px;
perspective: 600px;
}
.card {
width: 100%;
height: 100%;
position: relative;
transition: transform 1s;
transform-style: preserve-3d;
}
.card:hover{
transform:rotateY(180deg);
}
.card__face {
position: absolute;
height: 100%;
width: 100%;
backface-visibility: ;
/*works fine without backface-visibility:hidden */
}
.card__face--front {
background: red;
}
.card__face--back {
background: blue;
transform: rotateY( 180deg );
}
Link: https://codepen.io/nur49/pen/QWKaQRv
What it does is determine whether the image will show when flipped. A use case would be if you only have content on one side and not the other as in this example. If you don't add the css rule, you will still see it through the other side, but obviously backwards. Typically you do see flipcards with info on both sides, so most cases it might not be entirely necessary. Below is the code example from here.
body {
font-family: sans-serif;
font-size: 0.8rem;
}
div {
position: relative;
height: 60px;
width: 60px;
background-color: red;
transform: rotateY(180deg);
}
#div1 {
-webkit-backface-visibility: hidden; /* Safari */
backface-visibility: hidden;
}
#div2 {
-webkit-backface-visibility: hidden; /* Safari */
backface-visibility: visible;
}
<h1>The backface-visibility Property</h1>
<p>This example shows the back face of two div elements.</p>
<p>This div element has "backface-visibility: hidden", and the back face of the div element is invisible:</p>
<div id="div1">DIV 1</div>
<p>This div element has "backface-visibility: visible", and the back face of the div element shows a mirror image of the front face:</p>
<div id="div2">DIV 2</div>
<p><strong>Note:</strong> The backface-visibility property is not supported in Internet Explorer 9 and earlier versions. Safari supports it with a webkit prefix.</p>
I was trying to implement the paper flip transition using css, so in order to achieve that the tasks that I needed were:
I had to move the div from the current position to the left. I was able to achieve it using translate property.
I also had to flip the div. I was able to achieve it using scaleX(-1)
Finally I had to flip it in curve.
How can I achieve the final part? Here is a link to CSSDesk. I have tried the flip transition using hover.
I don't know if it's what ou were looking for, but here is a quick example :
/* entire container, keeps perspective */
.flip-container {
perspective: 1500px;
margin: 0 auto;
margin-top:100px;
}
/* flip the pane when hovered */
.flip-container:hover .flipper, .flip-container.hover .flipper {
transform: rotateY(180deg);
}
.flip-container, .front, .back {
width: 320px;
height: 480px;
}
/* flip speed goes here */
.flipper {
transition: 0.6s;
transform-style: preserve-3d;
transform-origin: 100%;
position: relative;
}
/* hide back of pane during swap */
.front, .back {
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
}
/* front pane, placed above back */
.front {
background-color:red;
z-index: 2;
/* for firefox 31 */
transform: rotateY(0deg);
}
/* back, initially hidden pane */
.back {
background-color:green;
transform: rotateY(180deg);
}
<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
<div class="flipper">
<div class="front">
<p>FRONT</p>
</div>
<div class="back">
<p>BACK</p>
</div>
</div>
</div>
The key to acheive 3d effect is perspective: 1500px;
This example is based on this amazing article which explain the property
I have two right triangle images that I want to put together like this (solid colors only for example):
I can think of a couple of ways to do this:
Divs with background images, and positioning them on top of each
other
A similar approach to the above, but with images instead of divs
The problem comes from the fact that I want to be able to hover (and click) on each individual triangle and have it change it's state (such as change color on hover).
Both of my above solutions create the problem where one is on top of the other, and I cannot click or hover over the other. I was thinking of doing this with CSS shapes, but those usually involve borders and I don't know of a way to overlay the image on those.
I need to be able to accomplish this with just CSS and HTML, and ideally without an image map.
Is this what you want?
Edit: I didn't notice there was another answer with similar approach, had the answer window opened for awhile, sorry.
.container {
width: 100px;
height: 100px;
overflow: hidden;
position: relative;
}
.triangle {
position: absolute;
width: 100px;
height: 100px;
top: 0;
left: 0;
overflow: hidden;
}
.triangle:hover {
border: 1px solid red;
}
.top_right {
transform: skewX(45deg);
transform-origin: 0 0;
}
.top_right img{
transform: skewX(-45deg);
transform-origin: 0 0;
}
.bottom_left {
transform: skewX(45deg);
transform-origin: 0 100%;
}
.bottom_left img{
transform: skewX(-45deg);
transform-origin: 0 100%;
}
<div class="container">
<div class="triangle top_right">
<img src="http://www.avatarsdb.com/avatars/spongebob_happy.jpg">
</div>
<div class="triangle bottom_left">
<img src="http://www.avatarsdb.com/avatars/say_cheese.jpg">
</div>
</div>
Another option is to use css skew:
your html:
<div class="img-container">
<img src="http://www.natureasia.com/common/img/splash/thailand.jpg" />
</div>
<div class="img-container">
<img src="http://www.worddive.com/blog/wp-content/uploads/2014/06/nature-and-environment-course.jpg"/>
</div>
The css:
.img-container, .img-container img { width: 100%; height: 100%; }
.img-container {
overflow: hidden;
position: absolute;
transform: skewX(-68deg);
}
.img-container:first-child {
left: -.25em;
transform-origin: 100% 0;
}
.img-container:last-child {
right: -.25em;
transform-origin: 0 100%;
}
.img-container img {
transform: skewX(68deg);
transform-origin: inherit;
}
It will probably work better with square images, however you can play around with the skew until it looks right.
Check out this Fiddle or rotating the other way
Again, not 100% sure on browser compatibility tho. If you need to guarantee that all browsers render properly you might be best of using images.
I've implemented a 3D flip effect in CSS to allow my div to have a front and back side (shows front by default, back on hover). The flip itself is working great, but there is another div at the end with a smaller height, and I can't seem to figure out how to push this div down past the one that flips. My goal is to have the flip div on a line, and the other image down below it instead of being covered up by the flip div.
And of course since we can't make this too easy, both the flip images and the image in the div below all have to be able to handle variable size images, they will never have set dimensions.
Here's the HTML:
<div class="images">
<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
<div class="flipper">
<div class="front">
<img src="http://www.placehold.it/350x450?text=front">
</div>
<div class="back">
<img src="http://www.placehold.it/350x450?text=back">
</div>
</div>
</div>
<br />
<div class="thumbnails columns-3" style=""><img src="http://www.placehold.it/350x150?text=image"></div>
</div>
And here's the CSS:
div.images {
float: left;
margin-bottom: 1em;
}
/* Flip3D */
/* entire container, keeps perspective */
.flip-container {
perspective: 1000;
}
/* flip the pane when hovered */
.flip-container:hover .flipper, .flip-container.hover .flipper {
transform: rotateY(180deg);
}
.flip-container, .front, .back {
/* width: 100%;
height: 100%;*/
}
/* flip speed goes here */
.flipper {
transition: 0.6s;
transform-style: preserve-3d;
}
/* hide back of pane during swap */
.front, .back {
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
}
/* front pane, placed above back */
.front {
z-index: 2;
/* for firefox 31 */
transform: rotateY(0deg);
}
/* back, initially hidden pane */
.back {
transform: rotateY(180deg);
}
Here's my fiddle: https://jsfiddle.net/8z2vbcrw/
Hopefully this all makes sense, but please ask me for clarification if not.
It can be done either by giving a height and width to your .flipper container or by just getting rid of absolute positioning on the front card...
https://jsfiddle.net/8z2vbcrw/
.front, .back {
backface-visibility: hidden;
top: 0;
left: 0;
}
.back {
position: absolute;
}
By doing this, the front card maintains the layout.
Example code here:
http://jsfiddle.net/gat5S/1/
I want to create a "card" that can be flipped via CSS rotateY. The rotation is based on David Walsh's CSS Flip Animation and in principle works well.
However, in my example, I have an :after pseudo-element for each side of the card that I use to create a paper-like shadow effect. This pseudo-element is put behind the card via negative z-index:-1;. This works for the "front" card but not after rotation and not for the "back" card.
The jsFiddle example code shows my problem (currently only containing webkit prefixes). In the initial state everthing looks as intended. The :after pseudo-element saying "INVISIBLE" is only partly visible. When you flip the card via the toggle button two things happen:
The front card :after element becomes visible. This is not intended.
The back card :after element is visible but also in the box where z-index:-1; should make it invisible. Also not intended.
I managed to solve 1. by using JavaScript to add a class to the .front which changes the visibility of :after. However, I cannot manage to solve 2. I tried different z-index values but these don't seem to have any effect at all.
I wonder if there is a clever way to solve both problems. Any help appreciated!
I've got it working
demo
CSS
.front, .back {
text-align: center;
background-color: #FFF9EC;
}
.front:after {
content: ' INVISIBLE ';
position: absolute;
width: 40%;
height: 10px;
left: 70px;
bottom: 12px;
z-index: -1;
-webkit-transform: translateZ(-1px);
-webkit-backface-visibility: hidden;
}
.back:after {
content: ' INVISIBLE ';
position: absolute;
width: 40%;
height: 10px;
left: 70px;
bottom: 12px;
z-index: -1;
-webkit-transform: translateZ(-1px);
-webkit-backface-visibility: hidden;
}
.flip-container {
-webkit-perspective: 1000;
}
/* flip the pane when hovered */
.flip-container.flip .flipper {
-webkit-transform: rotateY(180deg);
}
.flip-container, .front, .back {
width: 100px;
height: 100px;
}
/* flip speed goes here */
.flipper {
-webkit-transition: 0.6s;
-webkit-transform-style: preserve-3d;
position: relative;
left: 30px;
}
/* hide back of pane during swap */
.front, .back {
-webkit-backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
}
.back h1 {
-webkit-backface-visibility: hidden;
}
/* back, initially hidden pane */
.back {
-webkit-transform: rotateY(180deg) translateZ(1px);
-webkit-transform-style: preserve-3d;
-webkit-backface-visibility: hidden;
}
Mainly, I have changed the z-index to translateZ; that is the way you should work in 3D.
There was also some issue with the backface visibility : hidden not propagating to the child elements.