How do i vertically center align div with dynamic multiple line text - css

Below is the CSS i am using:
.flip-container
{
-webkit-perspective: 1000;
-moz-perspective: 1000;
perspective: 1000;
}
.flip-container:hover .flipper, .flip-container.hover .flipper {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.flip-container, .front, .back {
width: 150px;
height: 150px;
}
.flipper {
-webkit-transition: 0.6s;
-webkit-transform-style: preserve-3d;
-moz-transition: 0.6s;
-moz-transform-style: preserve-3d;
transition: 0.6s;
transform-style: preserve-3d;
position: relative;
}
.front, .back {
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
backface-visibility: hidden;
display: table-cell;
vertical-align:middle;
position: absolute;
top: 0;
left: 0;
}
.front {
z-index: 2;
text-align: center;
}
.back {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.front .name {
font-size: 2em;
display: inline-block;
background: rgba(33, 33, 33, 0.9);
color: #f8f8f8;
font-family: Courier;
padding: 5px 10px;
border-radius: 5px;
bottom: 60px;
left: 25%;
position: absolute;
text-shadow: 0.1em 0.1em 0.05em #333;
-webkit-transform: rotate(-20deg);
-moz-transform: rotate(-20deg);
transform: rotate(-20deg);
}
.back-logo {
position: absolute;
top: 40px;
left: 90px;
width: 160px;
height: 117px;
background: url(logo.png) 0 0 no-repeat;
}
.back-title {
font-weight: bold;
color: #00304a;
position: absolute;
top: 180px;
left: 0;
right: 0;
text-align: center;
text-shadow: 0.1em 0.1em 0.05em #acd7e5;
font-family: Courier;
font-size: 2em;
}
.back p {
position: absolute;
bottom: 40px;
left: 0;
right: 0;
text-align: center;
padding: 0 20px;
}
The HTML that i am using looks like this :
<div id="article"><div class="flip-container" ontouchstart="this.classList.toggle('.'hover'.');">
<div class="flipper">
<div class="front">
<!-- front content -->
</div>
<div class="back">
<!-- back content -->
<img src="" width="160" height="160" /> </div>
</div>
</div>
</div>
The CSS of the article class is:
#article {
margin: 5px;
float: left;
height: 150px;
width: 150px;}
I am unable to make the fext in the FRONT div center vertically centered. Also it would be dynamic and multiline. Any Ideas?
I tried using 'vertical-align:middle' along with 'display:table-cell' but that didn't help or maybe i just applied them to the wrong CSS Blocks.
The Code is on jsFiddle: here

You can use display: table for your parent container and display: table-cell for your child container:
#article {
display:table;
height: 150px;
width: 150px;
float: left;
text-align: center;
}
.front {
display: table-cell;
vertical-align:middle;
}
Fiddle Demo: http://jsfiddle.net/uVSN6/1/

Related

Weird overlay / flicker on css animation

When I animate a simple circle I get a weird flicker on the side - like something tryingh to push inside - and I can't figure out why. It also happens when I use keyframes to animate and on different browsers.
Any help appreciated.
.frame {
position: absolute;
top: 50%;
left: 50%;
width: 400px;
height: 400px;
margin-top: -200px;
margin-left: -200px;
border-radius: 2px;
box-shadow: 4px 8px 16px 0 rgba(0,0,0,0.1);
overflow: hidden;
background: #fff;
color: #333;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
background-color: #E56262;
}
.center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
z-index: 3;
}
.circle {
background-color: #fff;
width: 100px;
height: 100px;
border-radius:50%;
box-shadow: 0px 0 15px 2px #424040;
position: relative;
z-index: 4;
transition: all 1s;
}
.circle:hover {
transform: scale(1.5);
}
#keyframes scaleMe {
0% {
transform: scale(0%);
}
50% {
transform: scale(100%);
}
100% {
transform: scale(0%);
}
}
<div class="frame">
<div class="center">
<div class="circle"></div>
</div>
</div>
I think your problem is similar to this. CSS Animation break transform
Removing the transform(-50%, -50%) remove the flickering, so I centered your div in another way and it look's ok.
.frame {
position: absolute;
top: 50%;
left: 50%;
width: 400px;
height: 400px;
margin-top: -200px;
margin-left: -200px;
border-radius: 2px;
box-shadow: 4px 8px 16px 0 rgba(0,0,0,0.1);
overflow: hidden;
background: #fff;
color: #333;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
background-color: #E56262;
display: flex;
}
.center {
margin: auto;
z-index: 3;
}
.circle {
background-color: #fff;
width: 100px;
height: 100px;
border-radius:50%;
box-shadow: 0px 0 15px 2px #424040;
position: relative;
z-index: 4;
transition: all 1s;
}
.circle:hover {
transform: scale(1.5);
}
#keyframes scaleMe {
0% {
transform: scale(0%) translate(-50%,-50%);
}
50% {
transform: scale(100%) translate(-50%,-50%);
}
100% {
transform: scale(0%) translate(-50%,-50%);
}
}
<div class="frame">
<div class="center">
<div class="circle"></div>
</div>
</div>

Flip animation is broken when having inside element with position property

Flip animation is not working correctly if it has some element inside with position property. This can be only reproduced on the first hover attempt after the page load.
Does anyone know why it has such behavior?
HTML:
<div class="parent">
<div class="card">
<div class="card__logo">
Logo
</div>
<div class="card__burger">
<div class="relative">Menu</div>
</div>
</div>
</div>
SCSS:
.card {
width: 90px;
height: 90px;
transition: transform 1s;
transform-style: preserve-3d;
&__logo,
&__burger {
position: absolute;
cursor: pointer;
width: 100%;
height: 100%;
border-radius: 50%;
overflow: hidden;
backface-visibility: hidden;
background: #000;
color: #fff;
display: flex;
justify-content: center;
align-items: center;
}
&__burger {
transform: rotateY(180deg);
}
}
.parent:hover {
.card {
transform: rotateY(180deg);
}
}
.relative {
position: relative;
}
Codeopen example
Update: I can reproduce this only in Chrome
I have different code but this will help you.
<style>
.flip-card {
background-color: transparent; width: 100px;
height: 100px; perspective: 1000px; margin-left:16%;
}
.flip-card-inner {
position: relative; width: 100%; height: 100%;
text-align: center; transition: transform 0.6s; transform-style: preserve-3d;
}
.flip-card:hover .flip-card-inner { transform: rotateY(180deg); }
.flip-card-front, .flip-card-back {
position: absolute; width: 100%;
height: 100%; backface-visibility: hidden;
}
.flip-card-front {
background-color: #ffffff; color: black; z-index: 2;
}
.flip-card-back {
background-color: #ffffff; color: white;
transform: rotateY(180deg); z-index: 1;
}
.coninstallbtn { margin-top: 31%; margin-left: 20%; }
</style>
<body>
<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front">
Front View
</div>
<div class="flip-card-back">
Back View
</div>
</div>
</div>
</body>

CSS rotation create unwanted border around divs

I was trying to do the pie chart based on three divs. However, there's always some unwanted border around the divs. Also, they'll expand or shrink while zooming in and out.
Try many ways on other similar questions' solutions. Still can't work.
codepen link https://codepen.io/DavidLee0314/pen/PXWzYJ?editors=1100
* {
width: 100%;
height: 100%;
position: absolute;
margin: 0px;
padding: 0px;
}
.pie {
left: 40%;
top: 30%;
width: 174px;
height: 174px;
border-radius: 100%;
overflow: hidden;
display: flex;
justify-content: center;
font-size: 0px;
white-space: nowrap;
}
.pie .small-box {
width: 100%;
height: 100%;
}
.pie .grey {
transform: translateX(-50%);
background-color: #f3f5f2;
}
.pie .green {
transform: translateX(25%);
background-color: #222;
}
.pie .change {
transform-origin: left center 0;
transform: translateZ(0) scale(1, 1) translateX(50%) rotate(0deg);
background-color: #f3f5f2;
}
<div class="pie">
<div class="small-box green"></div>
<div class="small-box grey"></div>
<div class="small-box change"></div>
</div>
just use this at *:
Border: none:
* {
width: 100%;
height: 100%;
position: absolute;
margin: 0;
padding: 0;
border: none;
}
.pie{
left: 40%;
top: 30%;
width: 174px;
height: 174px;
border-radius: 100%;
overflow: hidden;
display: flex;
justify-content: center;
font-size: 0;
white-space: nowrap;
}
.small-box {
width: 100%;
height: 100%;
}
.grey {
transform: translateX(-50%);
background-color: #f3f5f2;
}
.green {
transform: translateX(25%);
}
.change {
transform-origin: left center 0;
transform: translateZ(0) scale(1.0, 1.0) translateX(50%) rotate(0deg);
background-color: #f3f5f2;
}
<div class="pie">
<div class="small-box green"></div>
<div class="small-box grey"></div>
<div class="small-box change"></div>
</div>

3D css - translate or rotate div with before and after pseudo content

Here is a jsbin of what I have so far.
I want to create a 3d hexagonal prism made up of 2 hexagons and some divs that will make up the body:
My hexagons are made up of the following markup:
<div class="hexagon-wrapper">
<div class="hexagon"></div>
</div>
The css uses the pseudo :before and :after selectors to create additional content that rotated 60 degrees to make the shape of the hexagon:
.hexagon-wrapper {
text-align: center;
position: relative;
width: 200px;
height: 200px;
}
.hexagon {
height: 100%;
width: 57.735%;
display: inline-block;
}
.hexagon:before {
position: absolute;
top: 0;
left: 50%;
background-color: inherit;
height: inherit;
width: inherit;
content: '';
transform: rotate(60deg);
transform-origin: 25% 25%;
}
.hexagon:after {
position: absolute;
top: 0;
left: 50%;
background-color: inherit;
height: inherit;
width: inherit;
content: '';
transform: rotate(-60deg);
transform-origin: 25% 75%;
}
The problem is, when I try and translate one of the hexagons:
.hexagon-wrapper:first-child .hexagon {
background-color: #D93;
transform: translateZ(100px);
}
The hexagon gets distorted as you can see here.
How can I translate or rotate the hexagon.
When you apply translateZ(X) to the parent it messes up the inherit values for width in the child.
The solution is to use width:100% instead of inherit but then the one without translateZ(X) will mess up. So the solution is to use translateZ(0) on it.
Demo
.hexagon:before {
position: absolute;
top: 0;
left: 50%;
background-color: inherit;
height: inherit;
width: 100%;
content: '';
transform: rotate(60deg);
transform-origin: 25% 25%;
}
.hexagon:after {
position: absolute;
top: 0;
left: 50%;
background-color: inherit;
height: inherit;
width: 100%;
content: '';
transform: rotate(-60deg);
transform-origin: 25% 75%;
}
.hexagon-wrapper:first-child .hexagon {
background-color: #D93;
transform: translateZ(100px);
}
.hexagon-wrapper:nth-child(2) .hexagon {
background-color: #6C6;
transform: translateZ(0);
}
3D Rotating Pentagon Code
#stage {
margin: 75px auto 0 auto;
max-width: 253px;
position: relative;
}
.spinner .face {
font-family: 'Montserrat', sans-serif;
position: absolute;
width: 280px;
height: 135px;
border: 1px solid rgba(0,0,0,0.2);
background: rgba(255,255,255,0.8);
box-shadow: inset 0 0 20px rgba(0,0,0,0.2);
text-align: center;
line-height: 48px;
margin: 0 auto;
font-size: 14px;
padding: 4px 0;
}
.spinner .face--first {
background: tomato;
transform: rotateY( 0deg ) translateZ(100px);
}
.spinner .face--second {
background: orange;
transform: rotateX(72deg) translateZ(100px);
}
.spinner .face--third {
background: blue;
transform: rotateX(144deg) translateZ(100px);
}
.spinner .face--fourth {
/*background: lime;*/
transform: rotateX(216deg) translateZ(100px);
}
.spinner .face--fifth {
background: red;
transform: rotateX(-72deg) translateZ(100px);
}
.spinner {
animation: spincube 8s infinite linear;
/*transform:rotateY(96deg);*/
position: relative;
transform-style: preserve-3d;
}
#-webkit-keyframes spincube {
from {
transform: rotateX(0deg) rotateY(0deg);
}
to {
transform: rotateX(360deg) rotateY(360deg);
}
}
#pentagon {
width:380px;
height:380px;
z-index: 11111;
overflow: hidden;
}
#pentagon .inner {
width: inherit;
height: inherit;
overflow: hidden;
-webkit-transform:scaleY(1.05146) skewX(-19deg) rotate(36deg) translateY(-36.33%) rotate(18deg) skewY(54deg) scaleX(0.58779);
transform: scaleY(1.05146) skewX(-19deg) rotate(36deg) translateY(-36.33%) rotate(18deg) skewY(54deg) scaleX(0.58779);
}
#pentagon .inner:before {
width: inherit;
height: inherit;
display: block;
content: '';
background:#333 url(surface_side_default.jpg) no-repeat right bottom;
background-size: 78% 62%;
background-position: 22px 158px;
-webkit-transform: scaleX(1.7013) skewY(-54deg) rotate(-18deg) translateY(-12.67%);
transform:scaleX(1.7013) skewY(-54deg) rotate(-18deg) translateY(-12.67%);
}
.transide1{
position: absolute;
-webkit-transform:rotateX(-18deg) rotateY(-90deg) skewX(19deg) scaleY(0.95106) translateX(-80px) translateY(-34px) translateZ(-92px);
transform:rotateX(-18deg) rotateY(-90deg) skewX(19deg) scaleY(0.95106) translateX(-80px) translateY(-34px) translateZ(-92px);
}
.transide2{
-webkit-transform:rotateX(-18deg) rotateY(-90deg) skewX(19deg) scaleY(0.95106) translateX(-80px) translateY(-34px) translateZ(190px);
transform:rotateX(-18deg) rotateY(-90deg) skewX(19deg) scaleY(0.95106) translateX(-80px) translateY(-34px) translateZ(190px);
}
<div id="stage">
<div class="spinner">
<div id="pentagon" class=" transide1"><div class="inner"></div></div>
<div class="face face--first"><img src="surface_side_default.jpg" height="140" width="280" /></div>
<div class="face face--first"><img src="surface_side_default.jpg" height="140" width="280" /></div>
<div class="face face--second"><img src="surface_side_default.jpg" height="140" width="280" /></div>
<div class="face face--third"><img src="surface_side_default.jpg" height="140" width="280" /></div>
<div class="face face--fourth"><img src="surface_side_default.jpg" height="140" width="280" /></div>
<div class="face face--fifth"><img src="surface_side_default.jpg" height="140" width="280" /></div>
<div id="pentagon" class=" transide2"><div class="inner"></div></div>
</div>
</div>

3D transform issue in firefox

I have a JSFiddle showing a flipping card, It works in chrome as I would expect but the depth perspective in firefox is flat and I'm not sure where the issue is.
I have tried adding:
transform-style: preserve-3d;
and
perspective: 1000;
to all classes (like card) I could with no luck.
The HTML structure is:
<div id="card-container">
<button id="card-flip">Flip the card</button>
<div id="card">
<div class="front card-surface"><!-- front -->
<p>The front</p>
</div>
<div class="back card-surface"><!-- back -->
<p>The back</p>
</div>
</div>
</div>
The simplified CSS is:
#card-container{
position: relative;
background-color:#888;
width: 300px;
height: 450px;
margin:0 auto;
}
#card-flip{
display:none;
}
#card{
margin:10px auto;
width: 100%;
height: 400px;
}
.card-surface{
margin-top:5px;
width: 280px;
height: 180px;
padding:10px;
}
.front{
background-color:#7B78E8;
}
.back{
background-color:#78AFE8;
}
/* Only apply 3d effects if they exist in the browser */
#card-container.threed{
height: 250px;
perspective: 1000;
}
.threed #card-flip{
background-color:transparent;
position:relative;
top:220px;
width:100%;
height:40px;
background-color:#99E5FF;
}
.threed #card-flip:focus{
outline:0;
}
.threed #card-flip:hover{
background-color:#49A5BF;
}
#card-flip:hover + #card .card-surface{
box-shadow: 0 0px 50px rgba(0,0,0,0.9);
transition: all .8s ease-in-out;
}
.threed #card{
height:200px;
}
.threed #card .front {
float: none;
position: absolute;
top: 0;
left: 0;
z-index: 900;
transform: rotateX(0deg) rotateY(0deg);
transform-style: preserve-3d;
backface-visibility: hidden;
}
.threed #card.flip .front {
z-index: 900;
border-color: #eee;
background: #333;
box-shadow: 0 15px 50px rgba(0,0,0,0.2);
transform: rotateY(180deg);
}
.threed #card .back {
float: none;
position: absolute;
top: 0;
left: 0;
z-index: 800;
border: 1px solid #ccc;
text-shadow: 1px 1px 1px rgba(0,0,0,0.6);
transform: rotateY(-180deg);
transform-style: preserve-3d;
backface-visibility: hidden;
}
.threed #card.flip .back {
z-index: 1000;
background-color:#ccc;
transform: rotateX(0deg) rotateY(0deg);
}
.threed #card .card-surface{
background-color:$base-white;
transition: all .8s ease-in-out;
width: 280px;
height: 180px;
padding:10px;
}
I have seen working examples like This one. Can anyone tell me what I am missing or is it not possible with this structure?
I have figured out the issue.
Here is a new version of the fiddle.
The problem was that I did not have the px after the perspective property. this was ignored by chrome but not firefox. I also applied The perspective to the wrong element in the demo so even though I had tried to ad the px before it didn't work.

Resources