CSS transform transition backface-visibility not working - css

I'm creating a transition that flips a contact card (link) but the backface-visibility property is giving me problems.
As can be seen in the codepen, nothing disappears after being flipped (even though it has turned its "backface" to the screen).
I tried creating a child div inside the card, to inherit its size and tried flipping it from the start so that, when the card were to be flipped, that div would have been on its front side and covered the rest.
The backface-visibility, though, doesn't work on that child div:
.cardBack{
padding:20px 50px;
background-color:white;
position:absolute;
width:inherit;
height:inherit;
backface-visibility:hidden;
transform:rotateX(180deg);
z-index:101;
}
If I either remove the transform:rotateX or the backface-visibility property, the .cardBack div covers the rest of the content both when the card is flipped and unflipped.
If I remove them both, it does the exact opposite of what I want: the .cardBack div obscures the content when the card is not flipped, and becomes invisible when the card is flipped.
If I leave it like this, the .cardBack div is never visible.

Here's the updated code.
Chrome has a weird bug when rotating elements, so backface-visibility was needed after all, just not on the .card itself.
$(document).ready(function(){
$(".card").click(function(){
$(this).toggleClass("turned");
$(this).toggleClass("unturned");
});
});
body{
background-color:#5AEDBC;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
overflow:hidden;
}
.card:after{
box-sizing:border-box;
backface-visibility:hidden;
display:block;
content:'';
width:200px;
height:400px;
left:380px;
position:absolute;
background: cadetblue;
transform:rotateZ(-40deg);
backface-visibility:hidden;
}
.card{
padding:20px 50px;
overflow:hidden;
position:absolute;
width:350px;
height:120px;
display: flex;
justify-content: center;
align-items:center;
flex-direction: row;
background-color:white;
font-family:'Raleway', sans-serif;
border:5px solid rgba(0,100,100, 0.75);
color:#008A45;
margin-top:100px;
transition:all 1s ease;
transform-origin:0 100%;
transform-style: preserve-3d;
}
.cardBack {
width:100%;
height:100%;
position:absolute;
top: 0;
left: 0;
background-color:white;
z-index:101;
}
.card.unturned .cardBack{
opacity: 0;
transition: opacity 0.25s ease 0.25s;
}
.card.turned .cardBack{
opacity: 1;
transition: opacity 0s ease 0.15s;
}
/* this is needed for chrome */
.card > * {
backface-visibility: hidden;
}
/* */
.card.turned{
transition:all 1s cubic-bezier(.17,.67,.59,1.35);
transform:rotateX(-180deg);
}
.info{
display: flex;
justify-content: center;
flex-direction: column;
text-align:right;
backface-visibility:hidden;
}
.title{
font-size:26px;
font-weight:bold italic;
color:black;
padding:5px 0;
display:block;
}
.desc{
font-size:18px;
color:#ccc;
padding:5px 0;
display:block;
}
.img{
border-radius: 50%;
width: 90px;
height: 90px;
margin-left:20px;
backface-visibility:hidden;
z-index:100;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet"/>
<div class="card unturned">
<div class="cardBack"></div>
<div class="info"><span class="title">Interesting person 1</span><span class="desc">Description of the interesting person 1</span></div><img src="http://www.cavaros.com/site_media/img/icon-profile.png" class="img"/>
</div>
<div class="card unturned">
<div class="cardBack"></div>
<div class="info"><span class="title">Interesting person 2</span><span class="desc">Description of the interesting person 2</span></div><img src="http://www.cavaros.com/site_media/img/icon-profile.png" class="img"/>
</div>
<div class="card unturned">
<div class="cardBack"></div>
<div class="info"><span class="title">Interesting person 3</span><span class="desc">Description of the interesting person 3</span></div><img src="http://www.cavaros.com/site_media/img/icon-profile.png" class="img"/>
</div>
View on Codepen.io

Related

Is there a way to animate singularly after pseudo classes?

I am attempting to select different pseudo classes to change their color I have the following codepen
This are my elements:
<figure class="atom">
<div class="electron"></div>
<div class="electron"></div>
<div class="electron"></div>
<div class="electron"></div>
<div class="electron"></div>
</figure>
CSS
body{
background:#c3c2c2;
}
.atom-container{
display: flex;
justify-content: center;
align-items: center;
}
.electron{
border-radius:50%;
width:100%;
height:100%;
position:absolute;
top:0;
border:7px solid #D35353;
}
.electron:nth-child(2){
transform:rotate(72deg);
border:7px solid #D9DD92;
}
.electron:nth-child(3){
transform:rotate(-72deg);
border:7px solid #EFBDEB;
}
.electron:nth-child(4){
transform:rotate(-144deg);
border:7px solid #FF9A6A;
}
.electron:nth-child(5){
transform:rotate(144deg);
border:7px solid #93B7E6;
}
.electron:after{
content:"";
position:absolute;
border-radius:50%;
width:2px;
height:2px;
border:4px solid #EFBDEB;
background:#EFBDEB;
animation:rotate 1.90s linear infinite;
}
::selection{background:#000;color:#bbb;}
figure{
width:75px;
height:255px;
position:fixed;
top: 20%;
left: 40%;
transform:scale(1.2,1.2)
}
#keyframes rotate{
0%{bottom:-15px;left:20px;}
18%{bottom:60px;left:-15px;}
50%{bottom:210px;left:-5px;}
60%{bottom:245px;left:25px;}
70%{bottom:195px;left:55px;}
76%{bottom:150px;left:65px;}
90%{bottom:50px;left:55px;}
97%{bottom:-5px;left:40px;}
99%{bottom:-10px;left:25px;}
100%{bottom:-15px;left:20px;}
}
This question is solved in my already working codepen:
https://codepen.io/marcos-collado-segura/pen/wLPzPW
everything is there but I cannot color the electrons
I have tried : nth-child() of this 'afters'
I have to achieve this with pure CSS I am not using precompilers
its solved with this
.atom nth-child(1):after
(for example)

CSS: Hover target area at 50% of the item's height

I would like, same as when you hover a GIF shot on Dribbble, display a div with infos when the cursor is after/at 50% from top of the item height.
Tested example
I made this, this is working but a bit tricky… especially when you mouseout.
— http://codepen.io/anon/pen/meZbJK
Used CSS code
.item {
position:relative; width:960px;
&--infos {
opacity:0;
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
padding:0 10%;
text-align:center;
background:transparentize(#a7ecf8, 0.075);
transition:opacity 200ms ease-in-out;
}
p {
position:relative;
padding:0;
top:50%; transform:translateY(-50%);
}
strong {
display:inline-block;
margin-bottom:10px;
}
time {
color:#959595;
font-size:14px;
}
&--infos-target {
position:absolute;
bottom:0;
float:left;
width:100%;
height:50%;
}
&--infos-target:hover &--infos {
opacity:1;
top:-100%;
height:200%;
}
}
I made edits to your codepen to make it work.
Essentially, I took --infos out of --infos-target and used the ~ selector to grab it on hover. With that, I didn't have to do the top: -100%; height: 200% hack anymore.
Combine that with pointer-events: none on --infos and you're good to go.
Using z-index you can position the target above the info section and you're good to go.
The biggest issue here is that you cannot have links inside the info section because of pointer-events: none
http://codepen.io/anon/pen/XmLrgp
HTML
<div class="item">
<img src="http://lorempicsum.com/futurama/960/250/1" alt="">
<div class="item--infos-target">
</div>
<div class="item--infos">
<p>
<strong>Item title</strong>
<br>
<time datetime="2015-11-05 15:23:26" class="date">Added two weeks ago</time>
</p>
</div>
</div>
SCSS
.item {
position:relative; width: 960px;
&--infos {
opacity:0;
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
padding:0 10%;
text-align:center;
pointer-events: none;
background:transparentize(#a7ecf8, 0.075);
transition:opacity 200ms ease-in-out;
z-index: 9;
}
p {
position:relative;
padding:0;
top:50%; transform:translateY(-50%);
}
strong {
display:inline-block;
margin-bottom:10px;
}
time {
color:#959595;
font-size:14px;
}
&--infos-target {
position:absolute;
bottom:0;
float:left;
width:100%;
height:50%;
z-index: 10;
}
&--infos-target:hover ~ &--infos {
opacity:1;
}
}
I think we need a bit of trickery here.
Firstly we need to "hide" the top 50% of the div/image from acting as a hover point/trigger.
We can use an absolutely positioned pseudo-element for that.
This means we can use the image (rather than the div) as our hover trigger...but this causes issues as the overlay would stop the hover effect. We can disable that with pointer-events:none.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
text-align: center;
}
.parent {
display: inline-block;
margin: 25px;
position: relative;
overflow: hidden;
}
.parent img {
display: block;
}
.info {
position: absolute;
top:100%;
left: 0;
width: 100%;
height: 100%;
background: rgba(255,0,0,.5);
color:white;
line-height: 72px;
transition:top .25s ease;
pointer-events:none;
z-index:3;
}
.parent::before {
content: '';
position: absolute;
top:0;
left: 0;
height: 50%;
width: 100%;
background: rgba(0,0,0,.5); /* for demo visual reference */
z-index:2;
}
.parent img:hover ~ .info {
top:0;
}
<div class="parent">
<img src="http://lorempixel.com/g/200/200" alt="" />
<div class="info"><h3>Some Text</h3></div>
</div>

transition expanding menu divs expand in nav bar but pushes other menu divs down when the window is resized

Okay, so im learning html and css, so im relativly new to this. I have followed many youtube videos to create different layouts. However, I am having real trouble in with this particular tutorial that i followed (https://www.youtube.com/watch?v=Wwe2zOz030o).
In this tutorial it shows how to make a really cool nav bar using the css transition effect, however, when the window is resized and i hover to expand a div it moves all of the other divs down the page. i want the divs to remain in the container at all times whatever the size of the window. i'm hoping this is really simple...
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
#import url("styles.css");
</style>
</head>
<body>
<div id="container">
<a href="#"><div class="menu">
<p class="p1">HOME</p>
<p class="p2">THIS IS OUR INTRO </p>
</div>
</a>
<div class="menu1">
<p class="p1">GALLERY</p>
<p class="p2">THIS IS MY PHOTOGRAPHY GALLERY</p>
</div>
<div class="menu2">
<p class="p1">ART PROJECTS</p>
<p class="p2">MY ART COLLECTION</p>
</div>
<div class="menu3">
<p class="p1">CONTACT</p>
<p class="p2">CONTACT ME</p>
</div>
</div>
</body>
</html>
the CSS styles are...
a{text-decoration:none;
}
#container{
height: 125px;
width: auto;
background-color:rgba(0,0,0,1);
position: relative;
}
.menu{
height: 125px;
width: 150px;
background-color: rgba(139,62,181,1);
float: left;
transition: all .5s ease-in-out 0s;
}
.menu1{
height: 125px;
width: 150px;
background-color: rgba(255,153,0,1);
float: left;
transition: all .5s ease-in-out 0s;
}
.menu2{
height: 125px;
width: 150px;
background-color: rgba(53,108,255,1);
float: left;
transition: all .5s ease-in-out 0s;
}
.menu3{
height: 125px;
width: 150px;
background-color: rgba(154,44,21,1);
float: left;
transition: all .5s ease-in-out 0s;
}
.p1{
font-family: Verdana, Geneva, sans-serif;
font-size: 20px;
color: rgba(255,255,255,.7);
font-weight: bold;
position: relative;
width: 100px;
top: 0px;
left: 15px;
transition:all .2s ease-in-out 0s;
}
.p2{
font-family:Verdana, Geneva, sans-serif;
font-size:12px;
color: rgba(255,255,255,.5);
position:relative;
top:0px;
left: 11px;
transition:all .2s ease-in-out 0s;
}
.menu:hover{
width:900px;
}
.menu1:hover{
width:900px;
}
.menu2:hover{
width:900px;
}
.menu3:hover{
width:900px;
}
.menu:hover .p1{
color:rgba(255,255,255,1);
}
.menu:hover .p2{
color:rgba(255,255,255,1);
}
.menu1:hover .p1{
color:rgba(255,255,255,1);
}
.menu1:hover .p2{
color:rgba(255,255,255,1);
}
.menu2:hover .p1{
color:rgba(255,255,255,1);
}
.menu2:hover .p2{
color:rgba(255,255,255,1);
}
.menu3:hover .p1{
color:rgba(255,255,255,1);
}
.menu3:hover .p2{
color:rgba(255,255,255,1);
}
It is a good case to use "flexbox".
Please take a look at your code with implemented flexbox:
http://codepen.io/Nargus/pen/uymsI
I added only display: flex; and overflow:hidden; to #container.
Also added min-width for each menu item (the same as width) so that flexbox knows its limits.
Width in .menu*:hover may be as big as you wish, all extras will be cut by flexbox itself.
Flexbox is ok on all modern browsers: http://caniuse.com/#feat=flexbox

How to make the opacity layer same size as img

How to make the opacity layer the same size as the img.
Right now the opacity layer has the same size as my img, but that's only because I edited it too the same size, but when I make my screen smaller it won't be the same size anymore as the img.
PS: is there a way to make content: "Work"; show up in the middle of the img instead at the top?
fiddle:
http://jsfiddle.net/nSLXF/
Html:
<body>
<img id="logo" src="Images/logo.png" alt="Logo">
<hr id="line" size="4" color="#09b981" align="center">
<a id="reach" href="about.html"><img src="Images/Reach.png" alt="Reach"></a>
<a id="contact" href="contact.html"><img src="Images/contact.png" alt="contact"></a>
<a id="werk" href="work.html"> <img src="Images/work.png" alt="werk"> </a>
</body>
css:
#reach img
{
text-align: center;
display: block;
margin: 0 auto;
width: 100%;
height:auto;
}
#reach:after {
content:'Work';
color:#fff;
position:absolute;
margin-top:11.2%;
margin-left: 25.2%;
width:49.6%; height:40.3%;
top:0; left:0;
background:rgba(0,0,0,0.6);
opacity:0;
transition: all 0.8s;
-webkit-transition: all 0.8s;
font-size: 42px;
font-family: Helvetica;
}
#reach:hover:after
{
opacity:1;
}
In fact you set the size and left, top wrongly for the layer which is actually a :after element. You can just set left:0, top:0 and width:100%, height:100% for it and use position:relative for the a element. The size of img should fit the size of the parent a element:
#reach {
text-align: center;
display: block;
margin: 0 auto;
width: 50%;
position:relative; /* add this */
}
#reach:after {
content:'Work';
color:#fff;
position:absolute;
/* update this */
width:100%;
height:100%;
top:0;
left:0;
/*------*/
background:rgba(0,0,0,0.6);
opacity:0;
transition: all 0.8s;
-webkit-transition: all 0.8s;
font-size: 42px;
font-family: Helvetica;
}
Demo.

Overflow hidden break chrome

Can someone tell me how can I fix this on Chrome? On firefox it works perfectly.
div{position: relative; width:200px; height:200px; overflow:hidden;background-color:#fc0;}; div img{opacity:0.2; transition:all 0.5s}
The code is just a sample of how i am using it. The animation works perfectly on firefox, the image gets circled all the time, but on chrome, when the animation is happening the image is can be seen oout of the circle.
Any help?
Imagem http://studio3pixels.com/img.png
here is a workaround with background images, Hope this solution is good for you:
http://jsfiddle.net/yucp2/
<style>
#wrapper
{
width: 300px; height: 300px;
border-radius: 300px;
overflow: hidden;
border:solid 10px #000;
background-color: #f30;
z-index:3;
}
#wrapper span
{
width: 300px;
height: 300px;
top:0;
background-color: #cde;
transition: all 0.5s;
z-index:1;
overflow:hidden;
background-image:url(http://www.paixaoeamor.com/arquivos/fotos/A777C.jpg);
background-repeat:no-repeat;
background-size:100% 100%;
display:inline-block;
background-position:center center;
}
#wrapper:hover > span
{
opacity:.5;
background-size:120% 120%;
}
</style>
<div id="wrapper">
<span></span>
</div>

Resources