animation to start from center of div using css3 only - css

Okay here is the thing,
I have the animation centered in the middle of the page and it start automatically as soon as the page loads but I want the animation to start from the middle of the page, expanding towards the right size. Not from the top left corner!!
I know it can be done using jquery but I want to use only CSS.
Any thoughts will be greatly appreciated.
Here is what I have
http://jsfiddle.net/robcabrera/9gXNc/
#container{
width: 700px;
height:350px;
position:absolute;
left:50%;
top:50%;
margin:-175px 0 0 -350px;
}
#intro{
width: 700px;
height:350px;
box-shadow:15px 15px 15px #333;
-webkit-box-shadow:15px 15px 15px #333;/*Safari and Chrome*/
-moz-box-shadow:15px 15px 15px #333;/*Mozilla Firefox*/
border-top: 2px solid #ccc ;
border-left: 2px solid #ccc;
border-radius:10px;
-moz-border-radius:10px;
background: #fff;
animation:welcome 2s;
animation-timing-function:linear;
animation-play-state:running;
-webkit-animation:welcome 2s; /*Safari and Chrome*/
-webkit-animation-timing-function:linear;
-webkit-animation-play-state:running;
}
#keyframes welcome{
from{
width:0px;
height:0px;
}
to {
width: 700px;
height:350px;
}
}
/*Safari and Chrome*/
#-webkit-keyframes welcome{
from{ width:0px; height:0px;}
to {width: 700px; height:350px;}
}

Without changing your code too much:
removed #container - margin, now the container is centered in its top left corner
added margin-left, margin-top to the animation so the intro would animate left/up as it grew
added animation fill-mode: forwards to keep the intro in place when the animation was complete.
Demo Fiddle
CSS
#container {
width: 700px;
height:350px;
position:absolute;
left:50%;
top:50%;
/*margin:-175px 0 0 -350px;*/
}
#intro {
position: relative;
...
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
/*Safari and Chrome*/
-webkit-animation-timing-function:linear;
-webkit-animation-play-state:running;
}
Keyframes (only generic shown here)
#keyframes welcome {
from {
width:0px;
margin-left: 0;
margin-top: 0;
height:0px;
}
to {
width: 700px;
margin-left: -350px;
margin-top: -175px;
height:350px;
}
}

Related

Animating a box-shadow/text-shadow on a circular path?

I'm trying to use CSS animations to create the effect of a light source pointing down on an object, casting a shadow and moving in a circular motion around it. I've created a snippet below to show where I've gotten to so far.
It's sort-of close but at the moment (because I only have 4 keyframes) it's like the light source is moving along a square path. I'd like it to look like it was moving along a circular path.
The only solution I can think of to come close is to add a bunch of more keyframes and create a (for the sake of simplicity) a dodecagon-shaped path, but is there a simpler solution? Is there a type of timing function I could use to ease it into a smoother path? Or could I use some sort of Sass function to automatically calculate the intermediate keyframes?
I should have noted that once I get this working with box-shadows, I'd also like to apply the same method to text-shadows.
.container {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100vh;
}
.circle {
width: 200px;
height: 200px;
border-radius: 100%;
background-color: teal;
box-shadow: 50px 50px 5px darkgrey;
animation: orbit-shadow 5s linear infinite;
}
#keyframes orbit-shadow {
0% {
box-shadow: 50px 50px 5px darkgrey;
}
25% {
box-shadow: -50px 50px 5px darkgrey;
}
50% {
box-shadow: -50px -50px 5px darkgrey;
}
75% {
box-shadow: 50px -50px 5px darkgrey;
}
1000% {
box-shadow: 50px 50px 5px darkgrey;
}
}
<div class="container">
<div class="circle"></div>
</div>
You have to consider rotation for this. Use a pseudo element to avoid rotating the main element:
.container {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
position:relative;
z-index:0;
}
.circle {
width: 200px;
height: 200px;
margin:50px;
border-radius: 100%;
background-color: teal;
position:relative;
}
.circle::before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
border-radius:inherit;
box-shadow: 50px 50px 5px darkgrey;
animation: orbit-shadow 5s linear infinite;
}
#keyframes orbit-shadow {
100% {
transform:rotate(360deg);
}
}
body{
margin:0;
}
<div class="container">
<div class="circle"></div>
</div>
Or you simply rotate the element if you won't have any content:
.container {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
}
.circle {
width: 200px;
height: 200px;
border-radius: 100%;
background-color: teal;
box-shadow: 50px 50px 5px darkgrey;
animation: orbit-shadow 5s linear infinite;
}
#keyframes orbit-shadow {
100% {
transform:rotate(360deg);
}
}
body{
margin:0;
}
<div class="container">
<div class="circle"></div>
</div>
Another idea:
.container {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
position:relative;
z-index:0;
}
.circle {
width: 200px;
height: 200px;
margin:50px;
border-radius: 100%;
background-color: teal;
position:relative;
}
.circle::before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
border-radius:inherit;
background:darkgrey;
filter:blur(5px);
animation: orbit-shadow 5s linear infinite;
}
#keyframes orbit-shadow {
0% {
transform:rotate(0deg) translate(50px);
}
100% {
transform:rotate(360deg) translate(50px);
}
}
body{
margin:0;
}
<div class="container">
<div class="circle"></div>
</div>
You can also do the same for text-shadow with a slightly different animation in order to not rotate the text:
.container {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
}
.circle {
position:relative;
font-size:40px;
font-weight:bold;
}
.circle::before,
.circle::after{
content:attr(data-text);
position:relative;
z-index:1;
}
.circle::before {
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
color:transparent;
text-shadow:0 0 5px darkgrey;
animation: orbit-shadow 5s linear infinite;
}
/* the 50px is your offset */
#keyframes orbit-shadow {
0% {
transform:rotate(0deg) translate(50px) rotate(0deg);
}
100% {
transform:rotate(360deg) translate(50px) rotate(-360deg);
}
}
body{
margin:0;
}
<div class="container">
<div class="circle" data-text="some text"></div>
</div>

Text appearing before animation delay

I use the following code for a text reveal animation but the text is already there before the 3 second delay that I declare. How can I fix this?
.header>span {
animation: slider 3s 3s ease-in;
overflow: hidden;
white-space: nowrap;
}
#keyframes slider {
0% {
max-width: 0%;
border-right: 4px solid #7CDD26;
}
99% {
max-width: 100%;
border-right: 4px solid #7CDD26;
}
100% {
max-width: 100%;
border-right: none;
}
}
<div class="header">
<span>This is some text</span>
</div>
you need at least inline-block (or block) to your span element to be able to use min-width then you need to add min-width:0% initially and add forwards to the animation to keep the last state:
.header>span {
animation: slider 3s 3s ease-in forwards;
overflow: hidden;
white-space: nowrap;
display:inline-block;
max-width: 0%;
}
#keyframes slider {
0% {
max-width: 0%;
border-right: 4px solid #7CDD26;
}
99% {
max-width: 100%;
border-right: 4px solid #7CDD26;
}
100% {
max-width: 100%;
border-right: none
}
}
<div class="header">
<span>This is some text</span>
</div>

I can't make my page scrollable with css

I'm unable to make my page scrollable. The code is:
body{
overflow-y: scroll;
margin: 0px;
padding: 0px;
}
#triangle-down { width: 0px; height: 0px;
border-left: 200px solid transparent;
border-right:200px solid transparent;
border-top: 230px solid white;
margin-left: 475px;
position:fixed;;
top: 65px;
z-index: -1;
}
div.topName {
margin-bottom:6px;
margin-left: 615px;
position: relative;
z-index:1;
}
body {
background-image: url("pictures/UHT_Plovdiv.png");
background-size: cover;
width: 50%;
background-color:0099CC;
}
div.boxwhitetop {
solid white ;
background-color: white;
width: 1200px;
height: 50px;
border-radius: 30px;
position: relative;
margin-left: 80px;
}
divMainbox{
border-radius: 35px;
background: white;
top: 7px;
left: -525px;
width: 1050px;
height: 1000px;
position:absolute;
text-align: center;
font-size: 25px;
overflow: hidden;
-webkit-animation: fadein 4.5s; /* Safari, Chrome and Opera > 12.1 */
-moz-animation: fadein 4.5s; /* Firefox < 16 */
-ms-animation: fadein 4.5s; /* Internet Explorer */
-o-animation: fadein 4.5s; /* Opera < 12.1 */
animation: fadein 4.5s;
overflow:hidden;
}
My github link is https://github.com/nedzone/uht-yniversitet, please tell me where my issue is and how can I fix this problem?
Just close your div in line number 23 in nachalna stanica.html, the page will start to scroll
<div id="triangle-down"></div>
If everything is going in the divMainbox then you shouldn't have a height on it. Otherwise it won't allow that container to resize based on the size of the content inside. Otherwise if you do want a specific height on that container then you should add a overflow-y: scroll; to it instead of the overflow: hidden; that you have now. This would allow you the container to have height, but also allow the user to scroll within it. Perhaps this is the trouble your having.

CSS Cart pop up box won't close with more than one product

I'm trying to create a pure css pop up box that automatically pops up when you visit the cart at my website to tell you about a special deal, and it works fine, up until you have more than one item in the cart, then for some reason it looks like it's creating multiple pop up boxes, and they won't close.
I was wondering if anyone might be able to help me figure out how to make the pop up close? Or possibly another solution to this?
Thank you,
a.popup-link {
padding:17px 0;
text-align: center;
margin:10% auto;
position: relative;
width: 300px;
color: #fff;
text-decoration: none;
background-color: #f87300;
border-radius: 3px;
box-shadow: 0 5px 0px 0px #eea900;
display: block;
}
a.popup-link:hover {
background-color: #ff9900;
box-shadow: 0 3px 0px 0px #eea900;
-webkit-transition:all 1s;
transition:all 1s;
}
#-webkit-keyframes autopopup {
from {opacity: 0;margin-top:-200px;}
to {opacity: 1;}
}
#-moz-keyframes autopopup {
from {opacity: 0;margin-top:-200px;}
to {opacity: 1;}
}
#keyframes autopopup {
from {opacity: 0;margin-top:-200px;}
to {opacity: 1;}
}
#popup {
position: fixed;
top:0;
left:0;
right:0;
bottom:0;
margin:0;
-webkit-animation:autopopup 2s;
-moz-animation:autopopup 2s;
animation:autopopup 2s;
z-index:9999;
}
#popup:target {
-webkit-transition:all 1s;
-moz-transition:all 1s;
transition:all 1s;
opacity: 0;
visibility: hidden;
}
#media (min-width: 768px){
.popup-container {
width:600px;
}
}
#media (max-width: 767px){
.popup-container {
width:100%;
}
}
.popup-container {
position: relative;
margin:7% auto;
padding:30px 50px;
background-color: #fafafa;
color:#333;
border-radius: 3px;
z-index:9999;
}
a.popup-close {
position: absolute;
top:3px;
right:3px;
background-color: #f87300;
padding:7px 10px;
font-size: 20px;
text-decoration: none;
line-height: 1;
color:#fff;
border-radius: 3px;
}
<div class="popup-wrapper" id="popup">
<div class="popup-container">
<h2>Spend $30...</h2>
<p>Spend $30 or more and get this free flag!</p>
<a class="popup-close" href="#popup">X</a>
</div>
</div>

CSS transition - tilting test-tube containing liquid

I have a simple CSS3 transition that involves a test tube, containing liquid, being tilted 60 degrees to the right.
Of course, liquid always stays on the horizontal plane, and it's this effect I'm having trouble with. I do have it working in a fashion, but the liquid's transition is far from convincing.
The idea was to simply rotate the liquid element, which is a child of the tube element, by the same but opposite degree, so -60. So the net, visual effect is the liquid stays at rotation 0deg. The liquid element has adequate width to allow for this rotation without showing white space.
Code Pen: http://codepen.io/anon/pen/sIDtp (currently has only -moz prefixes, no -webkit)
HTML:
<div id='container'>
<div id='tube'><div></div></div>
<div id='tube_bottom'></div>
</div>
CSS
div, button { display: block; position: relative; }
#container {
width: 50px;
height: 150px;
top: 30px;
margin: 0 auto;
transition: -moz-transform 1s
}
#container.transition { moz-transform: rotate(60deg); }
#tube {
border: solid 6px red;
border-top: none;
border-bottom: none;
width: 100%;
height: 100%;
z-index: 1;
background: #fff;
overflow: hidden;
}
#tube_bottom {
width: 100%;
height: 30%;
border-radius: 50%;
position: absolute;
bottom: -15%;
border: solid 6px red;
background: blue;
}
#tube div {
position: absolute;
left: -175px;
width: 400px;
height: 85%;
top: 30%;
background: blue;
transition: -moz-transform 1s, top 1s;
}
#container.transition #tube div { moz-transform: rotate(-60deg); top: 70%; }
As you can see, I'm having to also modify the top property, which isn't ideal and tells me I'm probably not going about this the right way. It almost looks as if the liquid element is failing to rotate about its central point (which I believe is the default value for transform-origin.
Can anyone give me some tips as to how to make this transition look natural?
Different approach : How about skewing the water?
This tube is made with :
one div and 2 pseudo elements
transform skew and rotate
box-shadows
DEMO (no vendor prefixes)
HTML :
<div class="tube"></div>
CSS :
.tube {
border: solid 6px red;
border-top: none;
border-bottom:none;
width:50px;
height:180px;
position:relative;
margin:0 auto;
transition:transform 1s;
}
.tube:after, .tube:before {
content:'';
position:absolute;
width:100%;
background:blue;
}
.tube:after {
top:100%;
left:-6px;
width:100%;
padding-bottom:100%;
border: solid 6px red;
border-top: none;
border-bottom-left-radius: 50%;
border-bottom-right-radius: 50%;
box-shadow: 0px -30px 0px -6px blue, 0px -50px 0px -6px blue;
}
.tube:before {
bottom:0;
height: 100px;
width:50px;
z-index:-1;
transition:transform 1s;
}
.tube:hover {
transform: rotate(60deg);
}
.tube:hover:before {
transform: skewY(-60deg);
}
Since the width perspective of the tube increases as it turns, the effect speed of the tilting liquid should be inversely proportional, slower when it turns, and faster when it gets back...
I got a better looking effect by setting a different transition speed for turn, and turn back:
Updated Codepen
#tube div {
position: absolute;
left: -175px;
width: 400px;
height: 85%;
top: 30%;
background: blue;
transition: -webkit-transform 1s, top 0.5s;
}
#container.transition #tube div {
-webkit-transform: rotate(-60deg);
transition: -webkit-transform 1s, top 1.4s;
top: 70%;
}
Though it could still get some improvements... (Sorry, I changed it all to -webkit-)
But perhaps you should consider using animation and #keyframes, so you could set specific values on each percentage of the transition.

Resources