I would like to display a css-grid which is full of flipcards. However, I found that if there isn't a non-flipcard element in a row of the css-grid, then it doesn't display properly: the rows overlap, the background-color isn't taken into account and the back side of the flipcard doesn't appear.
I think that the problem isn't linked with whichever version I use, for I also tested the following code in codepen.io and the problem is still there.
Here is my html:
<section class="grid-1">
<div class="flip-container item1">
<div class="flipper">
<div class="front">
1 front
</div>
<div class="back">
1 back
</div>
</div>
</div>
<div class="flip-container item2">
<div class="flipper">
<div class="front">
2 front
</div>
<div class="back">
2 back
</div>
</div>
</div>
<div class="flip-container item3">
<div class="flipper">
<div class="front">
3 front
</div>
<div class="back">
3 back
</div>
</div>
</div>
</section>
And here is my css:
body {
padding-top: 20px;
background: #f5f7f8;
}
.grid-1 {
display: grid;
padding-left: 20%;
padding-right: 20%;
width: 60%;
grid-template-columns: 1fr 1fr;
grid-auto-rows: 1fr;
grid-row-gap: 0.5%;
grid-template-areas: "item1 item2"
"item3 .";
}
.grid-1 div {
color: white;
font-size: 20px;
width: 100%;
height: 100%;
}
.item1{
grid-area: item1;
}
.item2{
grid-area:item2;
}
.item3{
grid-area: item3;
}
.flip-container {
background-color: transparent;
}
.flipper {
position: relative;
transition: transform 0.6s;
transform-style: preserve-3d;
}
.flip-container:hover .flipper {
transform: rotateY(180deg);
}
.front, .back {
position: absolute;
backface-visibility: hidden;
}
.front {
background-color: #bbb;
color: black !important;
}
.back {
background-color: #2980b9;
color: white;
transform: rotateY(180deg);
}
If the item1 or item2 is a simple div instead of a flip-container, then it all goes back to normal, the two rows don't overlap, the background-color is taken into account and the back side of the flipcard appears.
I would like to know where the problem lies, I'm quite a newbie css-wise so I don't really know where I should start to search.
Edit:
Thanks to Paulie_D, I now know how to do it, the answer is to set a height in px. However, I would also like to have a responsive grid, in which I will put images. How can I set a responsive height for element?
You have to give the elements a height...as the original 100% will not translate until the parent has a defined height.
body {
padding-top: 20px;
background: #f5f7f8;
}
.grid-1 {
display: grid;
padding-left: 20%;
padding-right: 20%;
width: 60%;
grid-template-columns: 1fr 1fr;
grid-auto-rows: 1fr;
grid-row-gap: 0.5%;
grid-template-areas: "item1 item2" "item3 .";
}
.grid-1 div {
color: white;
font-size: 20px;
width: 100%;
height: 100px;
}
.item1 {
grid-area: item1;
}
.item2 {
grid-area: item2;
}
.item3 {
grid-area: item3;
}
.flip-container {
background-color: transparent;
}
.flipper {
position: relative;
transition: transform 0.6s;
transform-style: preserve-3d;
}
.flip-container:hover .flipper {
transform: rotateY(180deg);
}
.front,
.back {
position: absolute;
backface-visibility: hidden;
}
.front {
background-color: #bbb;
color: black !important;
}
.back {
background-color: #2980b9;
color: white;
transform: rotateY(180deg);
}
<section class="grid-1">
<div class="flip-container item1">
<div class="flipper">
<div class="front">
1 front
</div>
<div class="back">
1 back
</div>
</div>
</div>
<div class="flip-container item2">
<div class="flipper">
<div class="front">
2 front
</div>
<div class="back">
2 back
</div>
</div>
</div>
<div class="flip-container item3">
<div class="flipper">
<div class="front">
3 front
</div>
<div class="back">
3 back
</div>
</div>
</div>
</section>
Related
I'm just learning the layout and I would like to make a page where there are blocks and lines between them and when you scroll, they will appear
I need to draw a vertical line that will connect the blocks, but so that it was adaptive.
I tried using skew, but it is not adaptive
.skill-l{
width: 100%;
height: min-content;
background-color: pink;
}
.skill-r{
width: 100%;
height: min-content;
text-align: end;
background-color: lightgreen;
}
.container-main{
margin-left: 33%;
margin-right: 33%;
}
.line-lr {
height: 50vh;
width: 3px;
background: green;
transform: skewX(30deg);
margin-left: 50%;
color: green;
}
.line-rl {
height: 50vh;
width: 3px;
background: yellow;
transform: skewX(-30deg);
color: yellow;
}
<div class="container-main">
<div class="skill-l text-white">
<h2>DIV 1</h2>
</div>
<div class="line-lr mx-auto">
</div>
<div class="skill-r text-white">
<h2>DIV 2</h2>
</div>
<div class="line-rl mx-auto"></div>
<div class="skill-l text-white">
<h2>DIV 3</h2>
</div>
</div>
My lines go over the block. How can I prevent that?
I am not able to use transform: translateZ to change the position of back div to create a 3d affect . There are no changes at all in the image. I have used perspective and perspective origin to try and create a 3d affect. The front and back div are respectively the front and back sides of a cube. Here is the below code written in css and html respectively
:root {
--boxColor: #0ff7
}
body {
align-items: center;
justify-content: center;
display: flex;
background-color: black;
min-height: 100vh;
font-size: 50px;
}
.scene {
position: relative;
transform-style: preserve-3d;
}
.cube-container {
perspective: 100px;
perspective-origin: 50% 0%;
}
.cube {
height: 100px;
width: 100px;
}
.front {
height: 100px;
width: 100px;
background: rgb(62, 86, 226);
opacity: 0.5;
}
.back {
height: 100px;
width: 100px;
background: rgb(62, 86, 226);
opacity: 0.5;
top: -100vh;
position: absolute;
transform: translateZ(100px)
}
<div class="scene">
<div class="cube-container">
<div class="cube">
<div class="front">
</div>
<div class="back">
</div>
<div class="top">
</div>
<div class="bottom">
</div>
<div class="left">
</div>
<div class="right">
</div>
</div>
</div>
</div>
You missed transform-style: preserve-3d; on .cube and I would also use position: absolute; for .front. I dont understand the perspective perfectly, but its common to use higher numbers like: perspective: 500px;.
Hope it helped! :)
:root {
--boxColor: #0ff7
}
body {
align-items: center;
justify-content: center;
display: flex;
background-color: black;
min-height: 100vh;
font-size: 50px;
}
.scene {
position: relative;
transform-style: preserve-3d;
}
.cube-container {
perspective: 500px;
perspective-origin: 50% 0%;
}
.cube {
height: 100px;
width: 100px;
transform-style: preserve-3d;
transform: rotateY(20deg);
}
.front {
position:absolute;
height: 100px;
width: 100px;
background: red;
opacity: 0.5;
}
.back {
position: absolute;
height: 100px;
width: 100px;
background: blue;
opacity: 0.9;
transform: translateZ(-100px);
}
<div class="scene">
<div class="cube-container">
<div class="cube">
<div class="front">
</div>
<div class="back">
</div>
<div class="top">
</div>
<div class="bottom">
</div>
<div class="left">
</div>
<div class="right">
</div>
</div>
</div>
</div>
I have created a masonry style grid in HTML/CSS. To do this I have used the
display:grid properties with 'grid-row' and 'grid-column.'
See attached pen.
This works great in Chrome, Firefox and Edge, not tried on Safari yet, but unfortunately, there are issues when it renders in the IE 11 browser.
Instead of getting a nice grid layout as shown in the attached pen it just displays 4 1x1 columns on top of one another.
Are there any IE specific properties that I can assign to my CSS classes in order to get this to display correctly across all browsers?
#container {
display:inline-block;
overflow: hidden; /* clip the excess when child gets bigger than parent */
}
#container img {
display: block;
transition: transform .4s; /* smoother zoom */
}
#container:hover img {
transform: scale(1.3);
transform-origin: 50% 50%;
}
.wrapper {
display: grid;
grid-gap: 0px;
grid-template-columns: 33% 33% 33%;
grid-template-rows: 400px 400px;
color: #000;
}
.a {
grid-column: 1;
grid-row: 1/3;
text-align:center;
color:#fff;
display:block;
position:relative;
overflow:hidden;
}
.b {
grid-column: 2 / span 2;
grid-row: 1;
color:#fff;
position:relative;
overflow:hidden;
}
.c {
grid-column: 2;
grid-row: 2;
color:#fff;
position:relative;
overflow:hidden;
}
.d {
grid-column: 3;
grid-row: 2;
color:#fff;
position:relative;
overflow:hidden;
}
.box {
border-radius: 0px;
padding: 10px;
font-size: 150%;
display:block;
position:relative;
}
.ctr {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%)
}
.imex-btn {
background-color: #4080fa;
border: none;
color: white;
padding: 10px 30px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin-top: 70px;
cursor: pointer;
font-family: "Century Gothic";
}
.imex-btn:hover {
background-color: #000;
color: #4080fa;
}
<div class="wrapper">
<div class="box a">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x900
C/O https://placeholder.com/">
<div class="ctr"><h2 class="white">BOX A<h2>
</div>
VIEW NOW
</div>
</div>
<div class="box b">
<div id="container">
<img id="image" src="https://via.placeholder.com/1200x900/C/O https://placeholder.com/">
<div class="ctr"><h2 class="white">BOX B</h2>
</div>
VIEW NOW
</div>
</div>
<div class="box c">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x500
C/O https://placeholder.com/">
<div class="ctr"><h2 class="white" style="text-align:center">BOX C</h2>
</div>
READ MORE
</div>
</div>
<div class="box d">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x500
C/O https://placeholder.com/">
<div class="ctr"><h2 class="white" style="text-align:center">BOX D</h2>
</div>
READ MORE
</div>
</div>
</div>
Try to change the CSS from
grid-template-columns: 33% 33% 33%;
To
grid-template-columns: 1fr 1fr 1fr;
Some elements are not properly rendered on IE11 due to their implementation of the standards.
Try adding a -ms- prefix to elements such as display: grid, grid-column and grid-row.
You will probably face the same kind of problems when testing on older versions of Safari (in which case try the -webkit prefix).
I've added some css to make it work in IE. Pay attention to the -ms- prefix added in css. You can also refer to this article which explains how to support css grid in IE.
#container {
display: inline-block;
overflow: hidden; /* clip the excess when child gets bigger than parent */
}
#container img {
display: block;
transition: transform .4s; /* smoother zoom */
}
#container:hover img {
transform: scale(1.3);
transform-origin: 50% 50%;
}
.wrapper {
display: -ms-grid;
display: grid;
grid-gap: 0px;
grid-template-columns: 33% 33% 33%;
-ms-grid-columns: 33% 33% 33%;
grid-template-rows: 400px 400px;
-ms-grid-rows: 400px 400px;
color: #000;
}
.a {
grid-column: 1;
grid-row: 1/3;
-ms-grid-column: 1;
-ms-grid-row-span: 2;
text-align: center;
color: #fff;
display: block;
position: relative;
overflow: hidden;
}
.b {
grid-column: 2 / span 2;
grid-row: 1;
-ms-grid-row:1;
-ms-grid-column-span: 2;
-ms-grid-column:2;
color: #fff;
position: relative;
overflow: hidden;
}
.c {
grid-column: 2;
grid-row: 2;
-ms-grid-column:2;
-ms-grid-row:2;
color: #fff;
position: relative;
overflow: hidden;
}
.d {
grid-column: 3;
grid-row: 2;
-ms-grid-column:3;
-ms-grid-row:2;
color: #fff;
position: relative;
overflow: hidden;
}
.box {
border-radius: 0px;
padding: 10px;
font-size: 150%;
display: block;
position: relative;
}
.ctr {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%)
}
.imex-btn {
background-color: #4080fa;
border: none;
color: white;
padding: 10px 30px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin-top: 70px;
cursor: pointer;
font-family: "Century Gothic";
}
.imex-btn:hover {
background-color: #000;
color: #4080fa;
}
<div class="wrapper">
<div class="box a">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x900
C/O https://placeholder.com/">
<div class="ctr">
<h2 class="white">BOX A</h2>
</div>
VIEW NOW
</div>
</div>
<div class="box b">
<div id="container">
<img id="image" src="https://via.placeholder.com/1200x900/C/O https://placeholder.com/">
<div class="ctr">
<h2 class="white">BOX B</h2>
</div>
VIEW NOW
</div>
</div>
<div class="box c">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x500
C/O https://placeholder.com/">
<div class="ctr">
<h2 class="white" style="text-align:center">BOX C</h2>
</div>
READ MORE
</div>
</div>
<div class="box d">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x500
C/O https://placeholder.com/">
<div class="ctr">
<h2 class="white" style="text-align:center">BOX D</h2>
</div>
READ MORE
</div>
</div>
</div>
I've built a card flip effect that seems to work on Safari Mobile regarding the "flip" aspect of the effect. However, the card is not displaying the correct image upon flipping. I'm using the effect as a "Before and After", using separate images on each side of the card. I'll post my code. Thank you.
.beforeafter {
margin: 10px auto;
text-align: center;
}
.card-container {
cursor: pointer;
height: 300px;
perspective: 600;
position: relative;
width: 300px;
display: inline-block;
}
.clientcard {
height: 100%;
position: absolute;
transform-style: preserve-3d;
transition: all .5s ease-in-out;
width: 100%;
}
.clientcard:hover {
transform: rotateY(180deg);
-webkit-transform: -webkit-translateY(180deg);
}
.clientcard .side {
backface-visibility: hidden;
border-radius: 2px;
height: 100%;
position: absolute;
overflow: hidden;
width: 100%;
}
.clientcard .back {
background: #eaeaed;
color: #0087cc;
line-height: 150px;
text-align: center;
transform: rotateY(180deg);
}
<div class="beforeafter">
<div class="card-container">
<div class="clientcard">
<div class="side"><img src="img/sean1.JPG"></div>
<div class="side back"><img src="img/sean1copy.JPG"></div>
</div>
</div>
<div class="card-container">
<div class="clientcard">
<div class="side"><img src="img/sean2.JPG"></div>
<div class="side back"><img src="img/sean2copy.JPG"></div>
</div>
</div>
<div class="card-container">
<div class="clientcard">
<div class="side"><img src="img/sean3copy.jpg"></div>
<div class="side back"><img src="img/sean3.jpg"></div>
</div>
</div>
<div class="card-container">
<div class="clientcard">
<div class="side"><img src="img/gwork.jpg"></div>
<div class="side back"><img src="img/alana2.jpeg"></div>
</div>
</div>
</div>
I believe you want to rotate on the Y axis in the negitive -180deg. I improved your code a bit and don't mind the shitty format it was translated from sass and if you want another card with flip copy and past that code
.card {
perspective: 150rem;
-moz-perspective: 150rem;
position: relative;
height: 52rem; }
.card_side {
height: 52rem;
transition: all 2s ease;
position: absolute;
top: 0;
left: 0;
width: 100%;
backface-visibility: hidden;
}
.card_side-front {
background-color: blue;
}
.card_side-back {
transform: rotateY(180deg);
}
.card_side-back-1 {
background-image: linear-gradient(to right bottom, #ffb900, #ff7730);
}
.card:hover .card_side-front {
transform: rotateY(-180deg);
}
.card:hover .card_side-back {
transform: rotateY(0);
}
.card_picture-1 {
background-color: blue;
}
<div class="row">
<div class="col-1-of-3">
<div class="card">
<div class="card_side card_side-front">
<h4 class="card_heading">
<span class="card_heading-span card_heading-span-1">card front text</span>
</h4>
</div>
<div class="card_side card_side-back card_side card_side-back-1">
<div class="card_cta">
<div class="card_price-box">
<p class="card_price-only">back text</p>
</div>
</div>
</div>
</div>
</div>
I have 4 boxes and I want to put them 2 x 2, but cannot figure out how to do it.
I have created a jsfiddle here
The issue I am having is that one of the boxes is above, and the other three are below.
I want it to look like this
My code is as follows for convenience.
html
<div class="wrap">
<div class="bg"></div>
<div class="main-container artists">
<div class="employee-box">
</div>
<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
<div class="flipper">
<div class="front employee-1">
<!-- front content -->
</div>
<div class="back">
<!-- back content -->
</div>
</div>
</div>
<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
<div class="flipper">
<div class="front employee-2">
<!-- front content -->
</div>
<div class="back">
<!-- front content -->
</div>
</div>
</div>
<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
<div class="flipper">
<div class="front employee-3">
<!-- front content -->
</div>
<div class="back">
<!-- back content -->
</div>
</div>
</div>
</div>
css
body{
height: 2000px;
}
.wrap {
height: 100%;
position: relative;
overflow: hidden;
}
.bg {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: -1;
background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/167792/mountains_copy.jpg') no-repeat center center;
background-size: cover;
transform: scale(1.1);
}
.employee-box {
background-color: red;
height: 250px;
width: 250px;
}
.employee-1 {
background: yellow;
}
.employee-2 {
background: pink;
}
.employee-3 {
background: green;
}
/* entire container, keeps perspective */
.flip-container {
perspective: 1000px;
display: inline-block;
}
.container-border{
border: 1px solid #ccc;
}
/* flip the pane when hovered */
.flip-container:hover .flipper, .flip-container.hover .flipper {
transform: rotateY(180deg);
}
.flip-container, .front, .back {
width: 250px;
height: 250px;
}
/* flip speed goes here */
.flipper {
transition: 0.8s;
transform-style: preserve-3d;
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 {
z-index: 2;
/* for firefox 31 */
transform: rotateY(0deg);
}
/* back, initially hidden pane */
.back {
transform: rotateY(180deg);
background-color: #fff;
}
you should add float: left; or display: inline-block; in the 1st box.
For examples:
.employee-box{
float: left;
}
Float:left on .employee-box and .flip-container will put them in position.
You may give a width to the main container and set each of those boxes inline-block, floatting or even use flex:
inline-block example:
body{
height: 2000px;
}
.wrap {
height: 100%;
position: relative;
overflow: hidden;
}
.bg {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: -1;
background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/167792/mountains_copy.jpg') no-repeat center center;
background-size: cover;
transform: scale(1.1);
}
.main-container.artists {
width:510px;
text-align:center;
margin:auto;
}
.employee-box {
background-color: red;
height: 250px;
width: 250px;
display: inline-block;
}
.employee-1 {
background: yellow;
}
.employee-2 {
background: pink;
}
.employee-3 {
background: green;
}
/* entire container, keeps perspective */
.flip-container {
perspective: 1000px;
display: inline-block;
}
.container-border{
border: 1px solid #ccc;
}
/* flip the pane when hovered */
.flip-container:hover .flipper, .flip-container.hover .flipper {
transform: rotateY(180deg);
}
.flip-container, .front, .back {
width: 250px;
height: 250px;
}
/* flip speed goes here */
.flipper {
transition: 0.8s;
transform-style: preserve-3d;
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 {
z-index: 2;
/* for firefox 31 */
transform: rotateY(0deg);
}
/* back, initially hidden pane */
.back {
transform: rotateY(180deg);
background-color: #fff;
}
<div class="wrap">
<div class="bg"></div>
<div class="main-container artists">
<div class="employee-box">
</div>
<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
<div class="flipper">
<div class="front employee-1">
<!-- front content -->
</div>
<div class="back">
<!-- back content -->
</div>
</div>
</div>
<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
<div class="flipper">
<div class="front employee-2">
<!-- front content -->
</div>
<div class="back">
<!-- front content -->
</div>
</div>
</div>
<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
<div class="flipper">
<div class="front employee-3">
<!-- front content -->
</div>
<div class="back">
<!-- back content -->
</div>
</div>
</div>
</div>