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>
Related
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´m trying to overlay images with a description and when the user hovers the mouse over the overlay it will move down and show the photo that is underneath.
However the overlays seem to be stuck like this. With what looks like the overlays stuck to the bottom adn when you hover the mouse nothing happens.
please excuse the images they´re just a random photo.
my html looks like this
<div class="Portfolio_container">
<div class="Portfolio">
<div class="section group">
<div class="col span_1_of_3">
<img src="Images/Dundee.jpg" alt="Avatar" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
<div class="col span_1_of_3">
<img src="Images/Dundee.jpg" alt="Avatar" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
<div class="col span_1_of_3">
<img src="Images/Dundee.jpg" alt="Avatar" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
</div>
</div>
</div>
and my CSS
.Portfolio_container {
background-color: #847470; /* colour of the whole portfolio page */
}
.Portfolio { /* keeps the examples in the middle with the background colour matching the container that surounds it*/
width: auto;
margin-right: 5%;
margin-left: 5%;
background-color: #847470;
}
/* SECTIONS */
.section {
clear: both;
padding: 0px;
margin: 0px;
}
/* COLUMN SETUP */
.col {
display: block;
float:left;
margin: 1% 0 1% 2%;
}
.col:first-child { margin-left: 0; }
/* GROUPING */
.group:before,
.group:after { content:""; display:table; }
.group:after { clear:both;}
.group { zoom:1; /* For IE 6/7 */ }
/* GRID OF THREE */
.span_3_of_3 { width: 100%; }
.span_2_of_3 { width: 66%; }
.span_1_of_3 { width: 32%; }
/* GO FULL WIDTH BELOW 480 PIXELS */
#media only screen and (max-width: 480px) {
.col { margin: 1% 0 1% 0%; }
.span_3_of_3, .span_2_of_3, .span_1_of_3 { width: 100%; }
}
.span_1_of_3 {
height: 100%;
}
.image {
max-width: 100%; /* keeps the portfolio images within their divs */
max-height: 100%;
display: block;
width: 100%;
height: auto;
}
.overlay {
bottom: 0;
left: 0;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 100%;
height: 100%;
transition: .5s ease;
opacity: 0.5;
}
.span_1_of_3:hover .overlay {
height: 0%;
}
.text {
color: white;
font-size: 20px;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
any help would be greatly appreciated.
found the solution.
.span_1_of_3 {
height: auto;
position: relative;
}
I had to make the div that was containing the overlays to have a relative position. Hopes this helps anyone who has this problem.
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>
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'm trying to make a responsive rectangular prism with depth that will resize with the window. But, no matter what I do, I can't get the bottom side to work correctly. It only lines up on the Z axis when the viewport has a square aspect ratio.
I had the same issue with the top side moving when I had it set to translateY(-50vh), but it starting behaving how I wanted when I changed it to -50vw (for some reason I can't figure out).
How can I make the bottom responsive like the top?
https://codepen.io/anon/pen/jwBQGR
.scene {
width: 100vw;
height: 100vh;
margin: 0 auto 0;
perspective: 3000px;
}
.rectangle {
position: relative;
width: 100%;
height: 100%;
transform-style: preserve-3d;
transform: translateZ(-50vw);
}
.side {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: visible;
}
.back {
transform: translateZ(-50vw);
background-color: saddlebrown;
}
.top {
background-color: lightblue;
height: 100vw;
transform: translateY(-50vw) rotateX(-90deg);
}
.bottom {
background-color: green;
height: 100vw;
transform: translateY(50vh) rotateX(90deg);
}
.front {
opacity: 0;
pointer-events: none;
}
.left {
background-color: sandybrown;
transform: translateX(-50vw) rotateY(-90deg);
}
.right {
background-color: brown;
transform: translateX(50vw) rotateY(90deg);
}
<div class="scene">
<div class="rectangle" id="cubeID">
<div class="side back">
<h1>Back</h1>
</div>
<div class="side top">
<h1>Top </h1>
</div>
<div class="side bottom">
<h1>Bottom</h1>
</div>
<div class="side front">
<h1>Front</h1>
</div>
<div class="side left">
<h1>Left</h1>
</div>
<div class="side right">
<h1>Right</h1>
</div>
</div>
</div>
The point is to use the transform-origin property (see transform-origin on MDN). This way, you can control the rotation axis for each side rather than repositioning them with translation after they have been rotated as you did.
Here is an example :
body,html{margin:0;}
.scene {
width: 100vw;
height: 100vh;
margin: 0 auto;
perspective: 3000px;
}
.rectangle {
position: relative;
width: 100%;
height: 100%;
transform-style: preserve-3d;
}
.side {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: visible;
}
.back {
transform: translateZ(-100vw);
background-color: saddlebrown;
}
.top {
background-color: lightblue;
height:100vw;
transform-origin:50% 0;
transform: rotateX(-90deg);
}
.bottom {
background-color: green;
height:100vw;
bottom:0;
transform-origin: 50% 100%;
transform: rotateX(90deg);
}
.front {
opacity: 0;
pointer-events: none;
}
.left {
background-color: sandybrown;
transform-origin:0 50%;
transform: rotateY(90deg);
}
.right {
background-color: brown;
transform-origin:100% 50%;
transform: rotateY(-90deg);
}
<div class="scene">
<div class="rectangle" id="cubeID">
<div class="side back"><h1>Back</h1></div>
<div class="side top"><h1>Top </h1></div>
<div class="side bottom"><h1>Bottom</h1></div>
<div class="side front"><h1>Front</h1></div>
<div class="side left"><h1>Left</h1></div>
<div class="side right"><h1>Right</h1></div>
</div>
</div>