CSS animate — how to fill div from center - css

In the fiddle below — I want the divs to fill in from the center, instead of from the top/left.
I've seen examples where margins are set in the keyframe, but that looks forever unclean to me.
Also, could I do this with transitions instead, is animate the best way to do this?
Here's the fiddle https://jsfiddle.net/hogue/mu0f6mk1/
.wrap {
position: relative;
margin: 0 auto;
width: 600px;
height: 600px;
cursor: pointer;
}
.wrap div {
border-radius: 10px;
box-shadow: inset 0 0 45px rgba(255, 255, 255, .3), 0 12px 20px -10px rgba(0, 0, 0, .4);
color: #FFF;
text-align: center;
text-shadow: 0 1px rgba(0, 0, 0, .3);
font: bold 3em sans-serif;
}
.first-layer {
background: #95a5a6;
width: 0px;
height: 0px;
position: absolute;
-webkit-animation: firstLayer 2s ease-in 0s forwards;
}
.second-layer {
background: #95a5a6;
width: 0px;
height: 0px;
position: absolute;
top: 8.5%;
left: 8.5%;
-webkit-animation: secondLayer 2s ease-in 0s forwards;
}
.third-layer {
background: #95a5a6;
width: 0px;
height: 0px;
position: absolute;
top: 17%;
left: 17%;
-webkit-animation: thirdLayer 2s ease-in 0s forwards;
}
.fourth-layer {
background: #95a5a6;
width: 0px;
height: 0px;
position: absolute;
top: 25%;
left: 25%;
-webkit-animation: fourthLayer 2s ease-in 0s forwards;
}
#-webkit-keyframes firstLayer {
to {
width: 400px;
height: 400px;
}
}
#-webkit-keyframes secondLayer {
to {
width: 300px;
height: 300px;
}
}
#-webkit-keyframes thirdLayer {
to {
width: 200px;
height: 200px;
}
}
#-webkit-keyframes fourthLayer {
to {
width: 100px;
height: 100px;
}
}
<div class="wrap">
<div class="first-layer"></div>
<div class="second-layer"></div>
<div class="third-layer"></div>
<div class="fourth-layer"></div>
</div>

I have repaired you the code
#-webkit-keyframes firstLayer {
from {
width: 0px;
margin-left: 0;
margin-top: 0;
height: 0px;
}
to {
width: 400px;
margin-left: -200px;
margin-top: -200px;
height: 400px;
}
}

Related

Two animations in CSS not working at the same time

I've created two animations with CSS a clock and a bouncing ball. Separately they both work as intended, but once I put them in the same file the bouncing ball disappeared.
If I delete #keyframes rotation the clock stops working but the bouncing ball appears. Is there any way how to make both animations work?
.clock {
position: relative;
width: 400px;
height: 400px;
border: 10px solid;
border-radius: 50%;
}
#second {
position: absolute;
background: black;
width: 2px;
height: 180px;
margin: 20px 199px;
animation: rotation 60s infinite linear;
transform-origin: bottom left;
}
#minute {
position: absolute;
background: black;
width: 6px;
height: 140px;
margin: 60px 197px;
animation: rotation 3600s infinite linear;
transform-origin: bottom right;
}
#hour {
position: absolute;
background: black;
width: 10px;
height: 120px;
margin: 80px 195px;
animation: rotation 43200s infinite linear;
transform-origin: bottom left;
}
#keyframes rotation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(359deg);
}
.box {
position: relative;
}
.ball {
position: absolute;
height: 100px;
width: 100px;
border: 3px solid pink;
border-radius: 50%;
animation: bounce 2s infinite;
background: pink;
}
.step1 {
position: absolute;
top: 150px;
height: 10px;
width: 220px;
background: cyan;
}
.step2 {
position: absolute;
top: 150px;
left: 220px;
margin-top: 20px;
height: 10px;
width: 220px;
background: cyan;
}
.step3 {
margin-top: 40px;
position: absolute;
left: 440px;
top: 150px;
height: 10px;
width: 220px;
background: cyan;
}
#keyframes bounce {
from {margin: 100pxz 0px;}
to{margin: 50px 500px;}
0% {
transform: translateY(-30%);
}
12% {
transform: translateY(33%);
}
24% {
transform: translateY(-66%);
}
36% {
transform: translateY(33%);
}
48% {
transform: translateY(-20%);
}
100% {
transform: translateY(33%);
}
<div class="clock">
<div id="hour"></div>
<div id="minute"></div>
<div id="second"></div>
</div>
<div class="box">
<div class="step1"></div>
<div class="step2"></div>
<div class="step3"></div>
<div class="ball"></div>
</div>
It works fine, you're/were missing the closing brackets on your keyframes
.clock {
position: relative;
width: 400px;
height: 400px;
border: 10px solid;
border-radius: 50%;
}
#second {
position: absolute;
background: black;
width: 2px;
height: 180px;
margin: 20px 199px;
animation: rotation 60s infinite linear;
transform-origin: bottom left;
}
#minute {
position: absolute;
background: black;
width: 6px;
height: 140px;
margin: 60px 197px;
animation: rotation 3600s infinite linear;
transform-origin: bottom right;
}
#hour {
position: absolute;
background: black;
width: 10px;
height: 120px;
margin: 80px 195px;
animation: rotation 43200s infinite linear;
transform-origin: bottom left;
}
#keyframes rotation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(359deg);
}
}
.box {
position: relative;
}
.ball {
position: absolute;
height: 100px;
width: 100px;
border: 3px solid pink;
border-radius: 50%;
animation: bounce 2s infinite;
background: pink;
}
.step1 {
position: absolute;
top: 150px;
height: 10px;
width: 220px;
background: cyan;
}
.step2 {
position: absolute;
top: 150px;
left: 220px;
margin-top: 20px;
height: 10px;
width: 220px;
background: cyan;
}
.step3 {
margin-top: 40px;
position: absolute;
left: 440px;
top: 150px;
height: 10px;
width: 220px;
background: cyan;
}
#keyframes bounce {
from {
margin: 100pxz 0px;
}
to {
margin: 50px 500px;
}
0% {
transform: translateY(-30%);
}
12% {
transform: translateY(33%);
}
24% {
transform: translateY(-66%);
}
36% {
transform: translateY(33%);
}
48% {
transform: translateY(-20%);
}
100% {
transform: translateY(33%);
}
}
<div class="clock">
<div id="hour"></div>
<div id="minute"></div>
<div id="second"></div>
</div>
<div class="box">
<div class="step1"></div>
<div class="step2"></div>
<div class="step3"></div>
<div class="ball"></div>
</div>

Css3 animations waves effect

I have created an container that if filling up and I want to apply to that some "waves animated effect" and I'm a bit stuck because I am not sure how to do it:
Does anyone cand help me with those waves effecct animations ?
body {
background-color: #015871;
}
.container {
position: relative;
width: 700px;
height: 300px;
margin: 100px auto;
}
.shape {
width: 200px;
height: 200px;
border-radius: 50%;
border-top-right-radius: 0;
transform: rotate(-45deg);
float: left;
margin-top: 50px;
margin-left: 20px;
border: 5px solid #fff;
overflow: hidden;
position: relative;
}
.frame {
position: absolute;
transform: rotate(225deg);
background-color: #00eaff;
bottom: -80px;
left: -80px;
right: 0;
height: 10px;
width: 200%;
animation: fill-up 1s ease infinite;
}
#keyframes fill-up {
to {
height: 300px;
}
}
<div class="container">
<div class="shape">
<div class="frame" />
</div>
</div>
working example: https://codesandbox.io/s/vigorous-keldysh-uw2po?file=/src/styles.css:81-720
Improved your code with inner element .wave with two rotating blocks. No JavaScript, no svg. Switch overflow hidden off to see how simple it works.
body {
background-color: #015871;
}
.container {
position: relative;
width: 700px;
height: 300px;
margin: 100px auto;
}
.shape {
width: 200px;
height: 200px;
border-radius: 50%;
border-top-right-radius: 0;
transform: rotate(-45deg);
float: left;
margin-top: 50px;
margin-left: 20px;
border: 5px solid #fff;
overflow: hidden;
position: relative;
}
.frame {
position: absolute;
transform: rotate(45deg);
background-color: rgba(0, 234, 255, 0.5);
bottom: -8px;
left: 15px;
right: 0;
height: 245px;
width: 200px;
}
.wave {
position: absolute;
top: 50%;
left: 0;
width: 200%;
height: 200%;
transform: translate(-25%, 0);
background: #4973ff;
animation: fill-up 10s ease infinite;
}
#keyframes fill-up {
to {
top: -60%;
}
}
.wave:before,
.wave:after {
content: '';
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 50%;
transform: translate(-50%, -75%);
background: #000;
}
.wave:before {
border-radius: 45%;
background: rgba(1, 88, 113, 1);
animation: animate 3s linear infinite;
}
.wave:after {
border-radius: 40%;
background: rgba(1, 88, 113, 0.5);
animation: animate 3s linear infinite;
}
#keyframes animate {
0% {
transform: translate(-50%, -75%) rotate(0deg);
}
100% {
transform: translate(-50%, -75%) rotate(360deg);
}
}
<div class="container">
<div class="shape">
<div class="frame">
<div class="wave">
</div>
</div>
</div>
</div>
Working example https://codepen.io/focus-style/pen/oNbxVBX

Create a CSS pulse effect from border outwards

I started creating a code pen with the effect I want here: https://codepen.io/oli_js/pen/KKPGZLm?editors=1100
However, this pulse effect radiates out from the centre point, but I want the inner circle to be transparent and just have the effect radiate just from the border.
Does anyone know of any any magical CSS wizardry to do this?!
.pulse {
border-radius: 50px;
height: 80px;
left: 50%;
letter-spacing: 0.05em;
line-height: 50px;
position: absolute;
text-align: center;
text-transform: uppercase;
top: 50%;
width: 80px;
}
.pulse:after {
-webkit-animation: pulse 2s infinite linear;
background: red;
border-radius: 50px;
content: '';
height: 100%;
left: 0;
opacity: 0;
position: absolute;
top: 0;
width: 100%;
}
.button {
background: transparent;
border-radius: 100% 100%;
width: 40px;
height: 40px;
left: 50%;
border:2px solid red;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
}
#-webkit-keyframes pulse{
0% {transform:scale(0.5);
opacity:0;}
33% {transform:scale(0.8);
opacity:1;}
100% {transform:scale(1);
opacity:0;}
}
<div class="pulse">
<div class="button"> </div>
</div>
You can do it with shadow effect too like this..
.ripple{
display: block;
width: 30px;
height: 30px;
border-radius: 50%;
border:2px red solid;
animation: pulse 2s infinite;
}
#-webkit-keyframes pulse {
0% {
-webkit-box-shadow: 0 0 0 0 rgba(255,0,0, 0.4);
}
70% {
-webkit-box-shadow: 0 0 0 10px rgba(255,0,0, 0);
}
100% {
-webkit-box-shadow: 0 0 0 0 rgba(255,0,0, 0);
}
}
<div class="ripple"></div>

How do I animate a square around a block?

My animation works but after one turn, the square rotate of 45 deg,
I don't understand why.
https://codepen.io/igamanstudio/pen/ZPYWWO
.card {
/* Add shadows to create the "card" effect */
position: relative;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.3s;
width: 300px;
height: 300px;
margin: 150px auto;
}
.anim-square {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
animation: spin 20s linear infinite;
}
.losange-wrap {
position: relative;
}
.losange-1 {
position: absolute;
overflow: hidden;
top: -15px;
left: -15px;
width: 30px;
height: 30px;
transform: rotate(45deg);
transform-origin: center;
background: red;
border: 2px solid blue;
animation: invert-spin 22.5s linear infinite;
}
.losange-1 .img {
position: relative;
width: 30px;
height: 30px;
}
.losange-1 .img:before {
position: absolute;
content: '';
display: block;
z-index: 999;
top: -15px;
left: -15px;
width: 60px;
height: 60px;
background: url("https://loremflickr.com/60/60/girl/all") center center;
transform: rotate(-45deg);
transform-origin: center;
}
/* On mouse-over, add a deeper shadow */
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}
/* Add some padding inside the card container */
.container {
padding: 2px 16px;
}
#keyframes spin {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#keyframes invert-spin {
100% {
-webkit-transform: rotate(-360deg);
transform: rotate(-360deg);
}
}
<div class="card">
<img src="http://placekitten.com/300/200" alt="Avatar" style="width:100%">
<div class="container">
<h4><b>John Doe</b></h4>
<p>Architect & Engineer</p>
</div>
<div class="anim-square">
<div class="losange-wrap">
<div class="losange-1">
<div class="img"></div>
</div>
</div>
</div>
</div>
transform: rotate(45deg);
transform-origin: center;
background: red ;
border: 2px solid blue;
animation: invert-spin 22.5s linear infinite;
First you need to set the same duration for both animation then you need to use rotate(-315deg) for the image since you are setting rotate(45deg). The difference should be 360deg like the main container that will animate from 0deg to 360deg
.card {
/* Add shadows to create the "card" effect */
position: relative;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.3s;
width: 300px;
height: 300px;
margin: 150px auto;
}
.anim-square {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
//background: rgba(0,0,0,0.3);
animation: spin 5s linear infinite;
}
.losange-wrap {
position: relative;
}
.losange-1 {
position: absolute;
overflow: hidden;
top: -15px;
left: -15px;
width: 30px;
height: 30px;
transform: rotate(45deg);
transform-origin: center;
background: red;
border: 2px solid blue;
animation: invert-spin 5s linear infinite;
}
.losange-1 .img {
position: relative;
width: 30px;
height: 30px;
}
.losange-1 .img:before {
position: absolute;
content: '';
display: block;
z-index: 999;
top: -15px;
left: -15px;
width: 60px;
height: 60px;
background: url('https://loremflickr.com/60/60/girl/all') center center;
transform: rotate(-45deg);
transform-origin: center;
}
/* On mouse-over, add a deeper shadow */
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}
/* Add some padding inside the card container */
.container {
padding: 2px 16px;
}
#keyframes spin {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#keyframes invert-spin {
100% {
-webkit-transform: rotate(-315deg);
transform: rotate(-315deg);
}
}
<div class="card">
<img src="http://placekitten.com/300/200" alt="Avatar" style="width:100%">
<div class="container">
<h4><b>John Doe</b></h4>
<p>Architect & Engineer</p>
</div>
<div class="anim-square">
<div class="losange-wrap">
<div class="losange-1">
<div class="img"></div>
</div>
</div>
</div>
</div>

Looping multiple css animation

I have a full css animation image comparison at the end with a packshot. I don't know how can i loop the full animation. Please help!
HTML:-
<div class='packshot' title='packshot'></div>
<div class='before' title='before'>
<div class='after' title='after'>
<textarea readonly cols='0' rows='0' class='container'></textarea>
</div>
</div>
<div class='brandstage' title='brandstage'></div>
CSS:-
html {
background: #fff;
height: 100%;
width: 100%;
}
.before {
background-image: url(http://design.cafecommunications.hu/skoda/4x4/before-after/kep01.jpg);
width: 640px;
height: 360px;
border: 0;
padding: 0;
margin: 0;
position: absolute;
overflow: hidden;
}
.after {
background-image: url(http://design.cafecommunications.hu/skoda/4x4/before-after/kep02.jpg);
height: 360px;
resize: horizontal;
position: absolute;
top: 0; left: 0;
min-width: 0;
max-width: 640px;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.after:before {
content: '⟨ ⟩';
background: rgba(0,0,0,.2);
font-size: 18px;
color: white;
top: 0; right: 0px;
height: 100%;
line-height: 440px;
position: absolute;
}
.brandstage {
background-image: url(http://design.cafecommunications.hu/skoda/4x4/before-after/new-brandstage.jpg);
width: 640px;
height: 80px;
border: 0;
padding: 0;
margin: 0;
position: absolute;
z-index: 101;
}
.container {
resize: horizontal;
opacity: 0;
position: relative;
top: 50%;
left: 0px;
margin-right: 0px;
width: 0px; height: 0px;
max-width: 634px; min-width: 12px;
outline: 0 solid transparent;
cursor: move;
cursor: all-scroll;
transform: scaley(35);
transform-origin: center center;
animation: intro 5s 1 normal ease-in-out 8s;
}
#keyframes intro {
0% {width: 0px}
30% {width: 640px}
60% {width: 0px}
100% {width: 640px}
}
.packshot {
background-image: url( http://design.cafecommunications.hu/skoda/4x4/before-after/kocsik.jpg);
width: 0%;
height: 100%;
background-repeat: no-repeat;
position: absolute;
transform-origin: center center;
animation: packshot 10s 1 normal ease-in-out 11s;
z-index: 100;
}
#keyframes packshot {
0% {width: 0%}
10% {width: 100%}
90% {width: 100%}
100% {width: 0%}
}
Add infinite to loop the keyframe calls and alternate to reverse the animation.
animation: intro 5s ease-in-out 8s alternate infinite;
animation: packshot 10s ease-in-out 11s alternate infinite;

Resources