CSS: backface-visibility not working? - html

I'm trying to create a card flipping effect, but I can't get the backface-visibility: hidden; working. What am I doing wrong?
.content {
width: 100%;
height: 70vh;
margin-left: auto;
margin-right: auto;
position: relative;
top: 50px;
}
.card {
margin: 10px;
width: 300px;
height: 450px;
border: 1px solid black;
float: left;
position: relative;
left: 10%;
background-color: green;
transition: all 0.6s ease;
}
.card:hover {
transform: rotateY(180deg);
}
.front, .back {
width: 300px;
height: 450px;
position: absolute;
backface-visibility: hidden;
}
<div class="content">
<div class="card">
<div class="front">
<p>hello</p>
</div>
<div class="back">
<p>goodbye</p>
</div>
</div>
</div>

Instead of rotating the parent, you have to rotate the two sides individually.
.content {
width: 100%;
height: 70vh;
margin-left: auto;
margin-right: auto;
position: relative;
top: 50px;
}
.card {
margin: 10px;
width: 300px;
height: 450px;
float: left;
position: relative;
left: 10%;
}
.front,
.back {
width: 300px;
height: 450px;
position: absolute;
backface-visibility: hidden;
transition-duration: 600ms;
border: 1px solid black;
}
.front {
background-color: green;
transform: none;
}
.back {
background-color: red;
transform: rotateY(180deg);
}
.card:hover .front {
transform: rotateY(180deg);
}
.card:hover .back {
transform: none;
}
<div class="content">
<div class="card">
<div class="front">
<p>hello</p>
</div>
<div class="back">
<p>goodbye</p>
</div>
</div>
</div>

http://jsfiddle.net/tj3eacxL/
Your original CSS is at the top. The necessary changes are:
.card {
-webkit-transform-style: preserve-3d;
background: none; /* Apply a background colour to the whole card to cover up the faces */
}
.back {
transform: rotateY(180deg); /* because the back should be flipped initially when it's in the back */
}
.front, .back {
background-color: green;
}

Here is a good example how do flip cards...
CSS:
.content {
perspective: 1000;
}
.content:hover .card {
transform: rotateY(180deg);
}
.content, .front, .back {
width: 300px;
height: 450px;
}
.front, .back {
border: 1px solid black;
background: green;
}
.card {
transition: 0.6s;
transform-style: preserve-3d;
position: relative;
}
.front, .back {
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
}
.front {
z-index: 2;
/* for firefox 31 */
transform: rotateY(0deg);
}
/* back, initially hidden pane */
.back {
transform: rotateY(180deg);
}
.content:hover .card {
transform: rotateY(180deg);
}

Related

Why is rotating element not showing?

Trying to create a rotating "card". The cover, inside-left, and inside-right all work fine. The back however is giving me issues. I applied the same rules to each panel so I don't know where the bug is coming from.
.scene {
margin-top: 10em;
margin-left: 20em;
width: 20em;
height: 20em;
perspective: 40em;
}
.cube {
width: 100%;
height: 100%;
position: relative;
animation: spinning 12s infinite;
transform-style: preserve-3d;
transform-origin: left;
}
#keyframes spinning {
from {
transform: translateY(5em) rotateY(0deg);
}
to {
transform: translateY(5em) rotateY(-360deg);
}
}
.front-left {
width: 60%;
height: 100%;
position: absolute;
line-height: 10em;
text-align: center;
transform-origin: left;
}
.panel-1 {
width: 100%;
height: 100%;
border-style: solid;
position: absolute;
backface-visibility: hidden;
}
.cover {
background-color: blue;
}
.left {
background-color: red;
transform: rotateY(180deg);
}
.right-back {
width: 60%;
height: 100%;
position: absolute;
line-height: 10em;
text-align: center;
transform: rotateY(130deg);
transform-origin: left;
}
.panel-2 {
width: 100%;
height: 100%;
border-style: solid;
position: absolute;
backface-visibility: hidden;
}
.end {
background-color: blue;
transform: rotateY(180deg);
}
.right {
background-color: red;
}
<div class="scene">
<div class="cube">
<div class="front-left">
<div class="panel-1 cover">cover</div>
<div class="panel-1 left">inner left</div>
</div>
<div class="right-back">
<div class="panel-2 end">back</div>
<div class="panel-2 right">inner right</div>
</div>
</div>
</div>
here is a fiddle of the code. https://jsfiddle.net/7xtv90as/
I suspect it might be because a transform is applied to the parent container but I am not sure.

CSS Cube not rotating properly

I am trying to make a cube with basic HTML and CSS. I have rotated every side on their position but on rotating the whole cube, I can see some blank area. Don't know what the problem is. Please help me solve this.
body {
width: 100vw;
height: 100vh;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center; }
#container {
position: relative;
width: 100px;
height: 100px;
border-radius: 20px;
background: transparent;
perspective: 9990px;
transform: rotateY(80deg);
transform-style: preserve-3d;
transform-origin: 50px 50px 0; }
#container .face {
width: 100px;
height: 100px;
background: #ddd;
position: absolute;
transition: all 0.2s;
backface-visibility: hidden;
border: 1px solid black; }
#container #face1 {
background: green;
transform: translateZ(-50px); }
#container #face2 {
background: red;
transform: translateX(50px) rotateY(90deg); }
#container #face3 {
background: blue;
transform: translateX(-50px) rotateY(90deg); }
#container #face4 {
background: yellow;
transform: translateZ(50px); }
#container #face5 {
background: purple;
transform: translateY(-50px) rotateX(90deg); }
#container #face6 {
background: cyan;
transform: translateY(50px) rotateX(90deg); }
<div id="container">
<div class="face" id="face1"></div>
<div class="face" id="face2"></div>
<div class="face" id="face3"></div>
<div class="face" id="face4"></div>
<div class="face" id="face5"></div>
<div class="face" id="face6"></div>
</div>
You are almost good, you need to define perspective on the body element (the parent of the cube) and you can get rid of backface-visibility: hidden;
body {
width: 100vw;
height: 100vh;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
perspective: 500px; /* here */
}
#container {
position: relative;
width: 100px;
height: 100px;
border-radius: 20px;
background: transparent;
transform: rotateY(20deg) rotateX(30deg);
transform-style: preserve-3d;
transform-origin: 50px 50px 0;
}
#container .face {
width: 100px;
height: 100px;
background: #ddd;
position: absolute;
transition: all 0.2s;
/*backface-visibility: hidden;*/
border: 1px solid black;
}
#container #face1 {
background: green;
transform: translateZ(-50px);
}
#container #face2 {
background: red;
transform: translateX(50px) rotateY(90deg);
}
#container #face3 {
background: blue;
transform: translateX(-50px) rotateY(90deg);
}
#container #face4 {
background: yellow;
transform: translateZ(50px);
}
#container #face5 {
background: purple;
transform: translateY(-50px) rotateX(90deg);
}
#container #face6 {
background: cyan;
transform: translateY(50px) rotateX(90deg);
}
<div id="container">
<div class="face" id="face1"></div>
<div class="face" id="face2"></div>
<div class="face" id="face3"></div>
<div class="face" id="face4"></div>
<div class="face" id="face5"></div>
<div class="face" id="face6"></div>
</div>
I just made a light edit on #container .face css rules, and the blank area is not visble. Is it well what you need ?
body {
width: 100vw;
height: 100vh;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center; }
#container {
position: relative;
width: 100px;
height: 100px;
border-radius: 20px;
background: transparent;
perspective: 9990px;
transform: rotateY(80deg);
transform-style: preserve-3d;
transform-origin: 50px 50px 0; }
#container .face {
width: 100px;
height: 100px;
background: #ddd;
position: absolute;
transition: all 0.2s;
backface-visibility: visible; /* changed from hidden to visible */
border: 1px solid black; }
#container #face1 {
background: green;
transform: translateZ(-50px); }
#container #face2 {
background: red;
transform: translateX(50px) rotateY(90deg); }
#container #face3 {
background: blue;
transform: translateX(-50px) rotateY(90deg); }
#container #face4 {
background: yellow;
transform: translateZ(50px); }
#container #face5 {
background: purple;
transform: translateY(-50px) rotateX(90deg); }
#container #face6 {
background: cyan;
transform: translateY(50px) rotateX(90deg); }
<div id="container">
<div class="face" id="face1"></div>
<div class="face" id="face2"></div>
<div class="face" id="face3"></div>
<div class="face" id="face4"></div>
<div class="face" id="face5"></div>
<div class="face" id="face6"></div>
</div>

Stop scrolling at the top of slider when click link href target id pure css

I have a pure css slider here but the problem is I dont want to scroll at the top of the slider when click the bullet and arrow navigation from the extra space.
Is there any way to achieve this with pure html or css?
I tried a href="#s3/" and a href="#s3!" but it's not working.
Looking for pure html and css solution since we have no script cms. Thanks
.wrapper {
overflow:scroll;
height:700px;
}
/* For visual purpose only */
.extra-space {
width: 100%;
height: 300px;
background: red;
line-height: 300px;
text-align: center;
}
/*slider*/
.CSSgal {
position: relative;
overflow: hidden;
/* Or set a fixed height */
}
/* SLIDER */
.CSSgal .slider {
height: 100%;
white-space: nowrap;
font-size: 0;
transition: 0.8s;
}
/* SLIDES */
.CSSgal .slider>* {
display: inline-block;
white-space: normal;
vertical-align: top;
height: 100%;
width: 100%;
background: none 50% no-repeat;
background-size: cover;
}
/* PREV/NEXT, CONTAINERS & ANCHORS */
.CSSgal .prevNext {
position: absolute;
z-index: 1;
top: 50%;
width: 100%;
height: 0;
}
.CSSgal .prevNext>div+div {
visibility: hidden;
/* Hide all but first P/N container */
}
.CSSgal .prevNext a {
text-align: center;
opacity: 0.7;
-webkit-transition: 0.3s;
transition: 0.3s;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
border-radius: 0;
position: absolute;
width: 30px;
height: 30px;
display: inline-block;
padding: 3px;
}
.CSSgal .prevNext .right {
right: 30px;
left: auto;
position: absolute;
top: 50%;
width: 50px;
height: 50px;
border-radius: 50%;
background-color: hsla(0, 0%, 92.2%, .6) !important;
z-index: 1;
cursor: pointer;
background-image: none !important;
transition: all .3s;
}
.CSSgal .prevNext .left {
left: 30px;
position: absolute;
top: 50%;
width: 50px;
height: 50px;
border-radius: 50%;
background-image: none !important;
background-color: hsla(0, 0%, 92.2%, .6) !important;
z-index: 1;
cursor: pointer;
transition: all .3s;
}
.CSSgal .prevNext .left:before {
content: "";
position: absolute;
width: 20px;
height: 20px;
background: url(https://new.brandsforless.ae/static/media/m-sprite.7b312d28.png) no-repeat;
background-size: 300px;
display: inline-block;
background-position: -76.5px -7px;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
}
.CSSgal .prevNext .right:before {
content: "";
position: absolute;
width: 20px;
height: 20px;
background: url(https://new.brandsforless.ae/static/media/m-sprite.7b312d28.png) no-repeat;
background-size: 300px;
display: inline-block;
background-position: -49px -7.5px;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
}
.CSSgal .prevNext a:hover {
background-color: #ebebeb!important;
}
.CSSgal .prevNext a+a {
left: auto;
right: 0;
}
/* NAVIGATION */
.CSSgal .bullets {
position: absolute;
z-index: 2;
bottom: 0;
padding: 10px 0;
width: 100%;
text-align: center;
}
.CSSgal .bullets>a {
display: inline-block;
width: 12px;
height: 12px;
border-radius: 50%;
background: #f8d000;
border: 2px solid #f8d000;
-webkit-transition: 0.3s;
transition: 0.3s;
}
.CSSgal .bullets a span {
display: none;
}
.right {
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
}
.left {
transform: rotate(135deg);
-webkit-transform: rotate(135deg);
}
.CSSgal .bullets>a+a {
background-color: rgba(255, 255, 255, 0.5);
border: 2px solid #999;
/* Dim all but first */
}
.CSSgal .bullets>a:hover {
background: #f8d000;
border: 2px solid #f8d000;
}
/* NAVIGATION BUTTONS */
/* ALL: */
.CSSgal>s:target~.bullets>* {
background-color: rgba(255, 255, 255, 0.5);
border: 2px solid #999;
}
/* ACTIVE */
#s1:target~.bullets>*:nth-child(1) {
background: #f8d000;
border: 2px solid #f8d000;
}
#s2:target~.bullets>*:nth-child(2) {
background: #f8d000;
border: 2px solid #f8d000;
}
#s3:target~.bullets>*:nth-child(3) {
background: #f8d000;
border: 2px solid #f8d000;
}
/* More slides? Add here more rules */
/* PREV/NEXT CONTAINERS VISIBILITY */
/* ALL: */
.CSSgal>s:target~.prevNext>* {
visibility: hidden;
}
/* ACTIVE: */
#s1:target~.prevNext>*:nth-child(1) {
visibility: visible;
}
#s2:target~.prevNext>*:nth-child(2) {
visibility: visible;
}
#s3:target~.prevNext>*:nth-child(3) {
visibility: visible;
}
/* More slides? Add here more rules */
/* SLIDER ANIMATION POSITIONS */
#s1:target~.slider {
transform: translateX(0%);
-webkit-transform: translateX(0%);
}
#s2:target~.slider {
transform: translateX(-100%);
-webkit-transform: translateX(-100%);
}
#s3:target~.slider {
transform: translateX(-200%);
-webkit-transform: translateX(-200%);
}
<div class="wrapper">
<section class="extra-space">
<h1>Extra space</h1>
</section>
<section class="mb-4">
<div class="container-fluid">
<div class="row">
<div class="col-12 p-0">
<div class="CSSgal">
<!-- Don't wrap targets in parent -->
<s id="s1"></s>
<s id="s2"></s>
<s id="s3"></s>
<div class="slider">
<div>
<a href="/en-ae/brands/troop-london/">
<img src="https://dummyimage.com/600x400/000/fff">
</a>
</div>
<div>
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div>
<img src="https://dummyimage.com/600x400/000/fff">
</div>
</div>
<div class="prevNext">
<div>
<a class="left" href="#s3"></a>
<a class="right" href="#s2"></a>
</div>
<div>
<a class="left" href="#s1"></a>
<a class="right" href="#s3"></a>
</div>
<div>
<a class="left" href="#s2"></a>
<a class="right" href="#s1"></a>
</div>
</div>
<div class="bullets">
<span>1</span>
<span>2</span>
<span>3</span>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
i manage to fix this by add s{display: none;} which hiding the id.
/*** the solution ***/
s{
display: none;
}
.wrapper {
overflow:scroll;
height:700px;
}
/* For visual purpose only */
.extra-space {
width: 100%;
height: 300px;
background: red;
line-height: 300px;
text-align: center;
}
/*slider*/
.CSSgal {
position: relative;
overflow: hidden;
/* Or set a fixed height */
}
/* SLIDER */
.CSSgal .slider {
height: 100%;
white-space: nowrap;
font-size: 0;
transition: 0.8s;
}
/* SLIDES */
.CSSgal .slider>* {
display: inline-block;
white-space: normal;
vertical-align: top;
height: 100%;
width: 100%;
background: none 50% no-repeat;
background-size: cover;
}
/* PREV/NEXT, CONTAINERS & ANCHORS */
.CSSgal .prevNext {
position: absolute;
z-index: 1;
top: 50%;
width: 100%;
height: 0;
}
.CSSgal .prevNext>div+div {
visibility: hidden;
/* Hide all but first P/N container */
}
.CSSgal .prevNext a {
text-align: center;
opacity: 0.7;
-webkit-transition: 0.3s;
transition: 0.3s;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
border-radius: 0;
position: absolute;
width: 30px;
height: 30px;
display: inline-block;
padding: 3px;
}
.CSSgal .prevNext .right {
right: 30px;
left: auto;
position: absolute;
top: 50%;
width: 50px;
height: 50px;
border-radius: 50%;
background-color: hsla(0, 0%, 92.2%, .6) !important;
z-index: 1;
cursor: pointer;
background-image: none !important;
transition: all .3s;
}
.CSSgal .prevNext .left {
left: 30px;
position: absolute;
top: 50%;
width: 50px;
height: 50px;
border-radius: 50%;
background-image: none !important;
background-color: hsla(0, 0%, 92.2%, .6) !important;
z-index: 1;
cursor: pointer;
transition: all .3s;
}
.CSSgal .prevNext .left:before {
content: "";
position: absolute;
width: 20px;
height: 20px;
background: url(https://new.brandsforless.ae/static/media/m-sprite.7b312d28.png) no-repeat;
background-size: 300px;
display: inline-block;
background-position: -76.5px -7px;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
}
.CSSgal .prevNext .right:before {
content: "";
position: absolute;
width: 20px;
height: 20px;
background: url(https://new.brandsforless.ae/static/media/m-sprite.7b312d28.png) no-repeat;
background-size: 300px;
display: inline-block;
background-position: -49px -7.5px;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
}
.CSSgal .prevNext a:hover {
background-color: #ebebeb!important;
}
.CSSgal .prevNext a+a {
left: auto;
right: 0;
}
/* NAVIGATION */
.CSSgal .bullets {
position: absolute;
z-index: 2;
bottom: 0;
padding: 10px 0;
width: 100%;
text-align: center;
}
.CSSgal .bullets>a {
display: inline-block;
width: 12px;
height: 12px;
border-radius: 50%;
background: #f8d000;
border: 2px solid #f8d000;
-webkit-transition: 0.3s;
transition: 0.3s;
}
.CSSgal .bullets a span {
display: none;
}
.right {
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
}
.left {
transform: rotate(135deg);
-webkit-transform: rotate(135deg);
}
.CSSgal .bullets>a+a {
background-color: rgba(255, 255, 255, 0.5);
border: 2px solid #999;
/* Dim all but first */
}
.CSSgal .bullets>a:hover {
background: #f8d000;
border: 2px solid #f8d000;
}
/* NAVIGATION BUTTONS */
/* ALL: */
.CSSgal>s:target~.bullets>* {
background-color: rgba(255, 255, 255, 0.5);
border: 2px solid #999;
}
/* ACTIVE */
#s1:target~.bullets>*:nth-child(1) {
background: #f8d000;
border: 2px solid #f8d000;
}
#s2:target~.bullets>*:nth-child(2) {
background: #f8d000;
border: 2px solid #f8d000;
}
#s3:target~.bullets>*:nth-child(3) {
background: #f8d000;
border: 2px solid #f8d000;
}
/* More slides? Add here more rules */
/* PREV/NEXT CONTAINERS VISIBILITY */
/* ALL: */
.CSSgal>s:target~.prevNext>* {
visibility: hidden;
}
/* ACTIVE: */
#s1:target~.prevNext>*:nth-child(1) {
visibility: visible;
}
#s2:target~.prevNext>*:nth-child(2) {
visibility: visible;
}
#s3:target~.prevNext>*:nth-child(3) {
visibility: visible;
}
/* More slides? Add here more rules */
/* SLIDER ANIMATION POSITIONS */
#s1:target~.slider {
transform: translateX(0%);
-webkit-transform: translateX(0%);
}
#s2:target~.slider {
transform: translateX(-100%);
-webkit-transform: translateX(-100%);
}
#s3:target~.slider {
transform: translateX(-200%);
-webkit-transform: translateX(-200%);
}
<div class="wrapper">
<section class="extra-space">
<h1>Extra space</h1>
</section>
<section class="mb-4">
<div class="container-fluid">
<div class="row">
<div class="col-12 p-0">
<div class="CSSgal">
<!-- Don't wrap targets in parent -->
<s id="s1"></s>
<s id="s2"></s>
<s id="s3"></s>
<div class="slider">
<div>
<a href="/en-ae/brands/troop-london/">
<img src="https://dummyimage.com/600x400/000/fff">
</a>
</div>
<div>
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div>
<img src="https://dummyimage.com/600x400/000/fff">
</div>
</div>
<div class="prevNext">
<div>
<a class="left" href="#s3"></a>
<a class="right" href="#s2"></a>
</div>
<div>
<a class="left" href="#s1"></a>
<a class="right" href="#s3"></a>
</div>
<div>
<a class="left" href="#s2"></a>
<a class="right" href="#s1"></a>
</div>
</div>
<div class="bullets">
<span>1</span>
<span>2</span>
<span>3</span>
</div>
</div>
</div>
</div>
</div>
</section>
</div>

How can I make a card flip with css click-event using an input box?

I'm trying to make a card-flip with CSS click-event using an input type that is hidden in the box that every time the user clicks the tile the box will flip and display the content on the back and when the user clicks the back tile it will flip again to the front tile. Here's my code snippet for more info:
.container {
padding: 12rem;
display: flex;
justify-content: center;
}
.tile {
perspective: 100rem;
-moz-perspective: 100rem;
position: relative;
width: 50%;
cursor: pointer;
margin-right: 5rem;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.tile-back, .tile-front {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.tile-back {
transform: rotateY(180deg);
}
.tile-back, .tile-back .card-body {
font-size: 1.5rem;
width: 50%;
text-align: center;
}
.card {
background-color: #58AA3F;
height: 20rem;
transition: all .8s ease;
position: absolute;
top: 0;
left: 0;
width: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
border-radius: 5px;
overflow: hidden;
box-shadow: 0 1.5rem 4rem rgba(0, 0, 0, 0.15);
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transition: all 600ms;
transition: all 600ms;
z-index: 20;
}
.card div {
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.card-body {
font-size: 2rem;
color: #fff;
text-align: center;
}
.card-footer {
font-size: 2rem;
}
.card:hover .card {
-webkit-transform: rotateX(20deg);
transform: rotateX(20deg);
box-shadow: 0 20px 20px rgba(50, 50, 50, 0.2);
}
.card input {
display: none;
}
.card :checked + .card {
transform: rotateX(180deg);
-webkit-transform: rotateX(180deg);
}
.card:hover :checked + .card {
transform: rotateX(160deg);
-webkit-transform: rotateX(160deg);
box-shadow: 0 20px 20px rgba(255, 255, 255, 0.2);
}
<div class="tile">
<input type="checkbox"/>
<div class="card tile-front">
<div class="card-body">
<p>Click to display back</p>
</div>
</div>
<div class="card tile-back">
<div class="card-body">
<p>Click to display front</p>
</div>
</div>
</div>
I don't if there's something missing in my code that the input isn't triggering.
I've made a few changes to your code.
For clarity I've left the checkbox visible, but you may hide it.
label[for=test] {
display:block;
-webkit-perspective: 800px;
perspective: 800px;
}
.reversible {
position: relative;
width: 250px;
margin: 50px auto;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transition: transform 1s ease;
transition: all 1s
}
input[type=checkbox]:checked + label .reversible {
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.reversible .card {
position: absolute;
left: 0;
top: 0;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.tile-front {
z-index: 2;
}
.tile-back {
-webkit-transform: rotateY( 180deg);
transform: rotateY( 180deg);
}
.card-body {
font-size: 2rem;
color: #fff;
text-align: center;
}
.card-footer {
font-size: 2rem;
}
.card {
background-color: #58AA3F;
height: 20rem;
transition: all .8s ease;
position: absolute;
top: 0;
left: 0;
width: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
border-radius: 5px;
overflow: hidden;
box-shadow: 0 1.5rem 4rem rgba(0, 0, 0, 0.15);
}
<input type="checkbox" id="test"/>
<label for="test">
<div class="reversible">
<div class="card tile-back">
<div class="card-body">
<p>Click to display back</p>
</div>
</div>
<div class="card tile-front">
<div class="card-body">
<p>Click to display front</p>
</div>
</div>
</div>
</label>
I hope it helps
Using this codepen as a basis, I changed it to work with a checkbox
body {
font-family: sans-serif;
}
.scene {
width: 200px;
height: 260px;
border: 1px solid #CCC;
margin: 10px 0;
perspective: 600px;
}
input {
display: none;
}
label {
width: 200px;
height: 260px;
}
.card {
width: 100%;
height: 100%;
transition: transform 1s;
transform-style: preserve-3d;
cursor: pointer;
position: relative;
}
#card:checked + label .card {
transform: rotateY(180deg);
}
.card__face {
position: absolute;
width: 100%;
height: 100%;
line-height: 260px;
color: white;
text-align: center;
font-weight: bold;
font-size: 40px;
backface-visibility: hidden;
}
.card__face--front {
background: red;
}
.card__face--back {
background: blue;
transform: rotateY(180deg);
}
<div class="scene scene--card">
<input id="card" type="checkbox">
<label for="card">
<div class="card">
<div class="card__face card__face--front">front</div>
<div class="card__face card__face--back">back</div>
</div>
</label>
</div>

CSS Hover Not Centering

I am creating a div which will enclose a users name and when they hover over a profile image then it will display the name over the image, when I am doing this it does not center the div over the image solely which will be causing a problem when styling the website.
My CSS is below:
.miniProfileImage {
border-radius: 100%;
border: 3px dashed #28A745;
width: 100%;
max-width: 200px;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
opacity: 1;
display: block;
}
.middle {
transition: .5s ease;
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
.img-container {
position: relative;
width: 50%;
}
.img-container:hover .miniProfileImage {
opacity: 0.3;
}
.img-container:hover .middle {
opacity: 1;
}
.middleText {
background-color: #4CAF50;
color: white;
font-size: 16px;
padding: 16px 32px;
}
A sample HTML mark-up can be seen here:
<div class='img-container'>
<img class='miniProfileImage' src='http://via.placeholder.com/500x500'>
<div class='middle'>
<p class='middleText'>Some Name</p>
</div>
</div>
I have also created a JS Fiddle to represent what is happening
.miniProfileImage {
border-radius: 100%;
border: 3px dashed #28A745;
width: 100%;
max-width: 200px;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
opacity: 1;
display: block;
}
.middle {
transition: .5s ease;
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
.img-container {
position: relative;
width: 50%;
}
.img-container:hover .miniProfileImage {
opacity: 0.3;
}
.img-container:hover .middle {
opacity: 1;
}
.middleText {
background-color: #4CAF50;
color: white;
font-size: 16px;
padding: 16px 32px;
}
<div class='img-container'>
<img class='miniProfileImage' src='http://via.placeholder.com/500x500'>
<div class='middle'>
<p class='middleText'>Some Name</p>
</div>
</div>
Thanks
That's because your surrounding <div class='img-container'> has a width that is wider than the image.
If you want the div to have the same size as the image, you can do the following:
.img-container {
position: relative;
display: inline-block;
}
.miniProfileImage {
border-radius: 100%;
border: 3px dashed #28A745;
width: 100%;
max-width: 200px;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
opacity: 1;
display: block;
}
.middle {
transition: .5s ease;
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
.img-container {
position: relative;
display: inline-block;
}
.img-container:hover .miniProfileImage {
opacity: 0.3;
}
.img-container:hover .middle {
opacity: 1;
}
.middleText {
background-color: #4CAF50;
color: white;
font-size: 16px;
padding: 16px 32px;
}
<div class='img-container'>
<img class='miniProfileImage' src='http://via.placeholder.com/500x500'>
<div class='middle'>
<p class='middleText'>Some Name</p>
</div>
</div>
please correct the CSS like this
.img-container {
position: relative;
width: 100%;
max-width: 210px;
}
and .middle {white-space:nowrap} you can give .miniProfileImage {max-width:100%} to image