I have dots moving up and down with a CSS animation, however I'd like to draw a dynamic curved line between them to create "Curved Chart" type look (a chart isn't the actual end goal, just the visual effect). How would I achieve this? Here's what I currently have:
The HTML Code:
<ul>
<li><span class="ball1"></span></li>
<li><span class="ball2"></span></li>
<li><span class="ball3"></span></li>
<li><span class="ball4"></span></li>
<li><span class="ball5"></span></li>
<li><span class="ball6"></span></li>
<li><span class="ball7"></span></li>
<li><span class="ball8"></span></li>
<li><span class="ball9"></span></li>
<li><span class="ball10"></span></li>
</ul>
The CSS Code:
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: white;
}
ul {
width: 340px;
height: 80px;
display: grid;
grid-template-columns: repeat(10, 1fr);
}
li {
display: flex;
justify-content: center;
position: relative;
}
li:before {
content: '';
width: 6px;
height: 90px;
position: absolute;
top: -5px;
border-radius: 90px;
}
span {
width: 20px;
height: 20px;
background: blue;
border-radius: 50%;
box-shadow: 0 0 20px -5px rgba(0, 0, 0, 0.3);
display: block;
animation: move 3s ease-in-out infinite alternate;
}
span.ball1 {
animation-delay: 0.25s;
}
span.ball2 {
animation-delay: 0.5s;
}
span.ball3 {
animation-delay: 0.75s;
}
span.ball4 {
animation-delay: 1s;
}
span.ball5 {
animation-delay: 1.25s;
}
span.ball6 {
animation-delay: 1.5s;
}
span.ball7 {
animation-delay: 1.75s;
}
span.ball8 {
animation-delay: 2s;
}
span.ball9 {
animation-delay: 2.25s;
}
span.ball10 {
animation-delay: 2.5s;
}
#keyframes move {
100% {
transform: translateY(58px);
}
}
Code Pen:
https://codepen.io/anon/pen/JwxJxO
Any help would be super useful, thank you!
You can add line between each circle to simulate such effect.
Here is a non-perfect example where I also used skew transformation to make the effect looks better (adjust the different value to get a perfect result like you want)
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: white;
}
ul {
width: 340px;
height: 80px;
display: grid;
grid-template-columns: repeat(10, 1fr);
}
li {
display: flex;
justify-content: center;
position: relative;
}
span {
width: 20px;
height: 20px;
background: blue;
border-radius: 50%;
box-shadow: 0 0 20px -5px rgba(0, 0, 0, 0.3);
display: block;
animation: move 3s ease-in-out infinite alternate;
position:relative;
transform: translateY(-29px);
}
li:not(:last-child) span::before {
content:"";
position:absolute;
top:50%;
left:100%;
width:20px;
height:2px;
background:blue;
animation-delay:inherit;
animation: skew 3s ease-in-out infinite alternate;
}
span.ball1 {
animation-delay: 0.25s;
}
span.ball2 {
animation-delay: 0.5s;
}
span.ball3 {
animation-delay: 0.75s;
}
span.ball4 {
animation-delay: 1s;
}
span.ball5 {
animation-delay: 1.25s;
}
span.ball6 {
animation-delay: 1.5s;
}
span.ball7 {
animation-delay: 1.75s;
}
span.ball8 {
animation-delay: 2s;
}
span.ball9 {
animation-delay: 2.25s;
}
span.ball10 {
animation-delay: 2.5s;
}
#keyframes move {
0% {
transform: translateY(-29px);
}
100% {
transform: translateY(29px);
}
}
#keyframes skew {
0% {
transform: skewY(13deg);
}
30% {
transform: skewY(10deg);
}
70% {
transform: skewY(-10deg);
}
100% {
transform: skewY(-13deg);
}
}
<ul>
<li><span class="ball1"></span></li>
<li><span class="ball2"></span></li>
<li><span class="ball3"></span></li>
<li><span class="ball4"></span></li>
<li><span class="ball5"></span></li>
<li><span class="ball6"></span></li>
<li><span class="ball7"></span></li>
<li><span class="ball8"></span></li>
<li><span class="ball9"></span></li>
<li><span class="ball10"></span></li>
</ul>
You can achieve this with kind of animations with canvas.
here's an example I found on codepen, which might be useful for your problem: https://codepen.io/nicolaszamarreno/pen/yXzGgG
Related
I have implemented a loading spinning icon which is overlaid on the page.
It looks fine but when I try to darken the entire page by using
background-color: rgba(0, 0, 0, 0.4);
in the .spinner-container element, the bands of the loading element dim also...
See these pictures...
I would like to keep these bright vibrant colors on top of the dimmed gray background.
Any ideas what I can implement to change this?
.spinner-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-color: rgba(0, 0, 0, 0.4);
}
#keyframes blink {
0% {
opacity: 0.2;
}
20% {
opacity: 1;
}
100% {
opacity: 0.2;
}
}
.three-dots span {
animation-name: blink;
animation-duration: 1.4s;
animation-iteration-count: infinite;
animation-fill-mode: both;
}
.three-dots span:nth-child(2) {
animation-delay: 0.2s;
}
.three-dots span:nth-child(3) {
animation-delay: 0.4s;
}
.spinner {
position: relative;
display: flex;
justify-content: center;
align-items: center;
width: 300px;
height: 300px;
}
.spinner-sector {
border-radius: 50%;
position: absolute;
width: 100%;
height: 100%;
border: 15px solid transparent;
mix-blend-mode: overlay;
}
.spinner-text {
font-size: 2em;
}
.spinner-sector-blue {
animation: rotate 2s ease-out infinite;
border-top: 15px solid lightblue;
}
.spinner-sector-red {
animation: rotate 2.5s ease-in infinite;
border-top: 15px solid lightcoral;
}
.spinner-sector-green {
animation: rotate 1.5s ease-in-out infinite;
border-top: 15px solid lightgreen;
}
#keyframes rotate {
from {
transform: rotate(0);
}
to {
transform: rotate(360deg);
}
}
#keyframes loading-opacity {
0%,
100% {
opacity: 1;
}
25%,
75% {
opacity: 0.5;
}
50% {
opacity: 0.1;
}
}
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="spinner-container">
<div class="spinner">
<div class="spinner-text three-dots">Loading<span>.</span><span>.</span><span>.</span></div>
<div class="spinner-sector spinner-sector-red"></div>
<div class="spinner-sector spinner-sector-blue"></div>
<div class="spinner-sector spinner-sector-green"></div>
</div>
</div>
</body>
</html>
You are using mix-blend-mode: overlay; (documentation) on your .spinner-sector elements, which is blending the vibrant colours with the darkened page below.
Removing that gives you:
.spinner-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-color: rgba(0, 0, 0, 0.4);
}
#keyframes blink {
0% {
opacity: 0.2;
}
20% {
opacity: 1;
}
100% {
opacity: 0.2;
}
}
.three-dots span {
animation-name: blink;
animation-duration: 1.4s;
animation-iteration-count: infinite;
animation-fill-mode: both;
}
.three-dots span:nth-child(2) {
animation-delay: 0.2s;
}
.three-dots span:nth-child(3) {
animation-delay: 0.4s;
}
.spinner {
position: relative;
display: flex;
justify-content: center;
align-items: center;
width: 300px;
height: 300px;
}
.spinner-sector {
border-radius: 50%;
position: absolute;
width: 100%;
height: 100%;
border: 15px solid transparent;
}
.spinner-text {
font-size: 2em;
}
.spinner-sector-blue {
animation: rotate 2s ease-out infinite;
border-top: 15px solid lightblue;
}
.spinner-sector-red {
animation: rotate 2.5s ease-in infinite;
border-top: 15px solid lightcoral;
}
.spinner-sector-green {
animation: rotate 1.5s ease-in-out infinite;
border-top: 15px solid lightgreen;
}
#keyframes rotate {
from {
transform: rotate(0);
}
to {
transform: rotate(360deg);
}
}
#keyframes loading-opacity {
0%,
100% {
opacity: 1;
}
25%,
75% {
opacity: 0.5;
}
50% {
opacity: 0.1;
}
}
<div class="spinner-container">
<div class="spinner">
<div class="spinner-text three-dots">Loading<span>.</span><span>.</span><span>.</span></div>
<div class="spinner-sector spinner-sector-red"></div>
<div class="spinner-sector spinner-sector-blue"></div>
<div class="spinner-sector spinner-sector-green"></div>
</div>
</div>
Alternatively, to keep the blending effect, you could switch to an option that doesn't darken the loading animation, e.g. hard-light
.spinner-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-color: rgba(0, 0, 0, 0.4);
}
#keyframes blink {
0% {
opacity: 0.2;
}
20% {
opacity: 1;
}
100% {
opacity: 0.2;
}
}
.three-dots span {
animation-name: blink;
animation-duration: 1.4s;
animation-iteration-count: infinite;
animation-fill-mode: both;
}
.three-dots span:nth-child(2) {
animation-delay: 0.2s;
}
.three-dots span:nth-child(3) {
animation-delay: 0.4s;
}
.spinner {
position: relative;
display: flex;
justify-content: center;
align-items: center;
width: 300px;
height: 300px;
}
.spinner-sector {
border-radius: 50%;
position: absolute;
width: 100%;
height: 100%;
border: 15px solid transparent;
mix-blend-mode: hard-light;
}
.spinner-text {
font-size: 2em;
}
.spinner-sector-blue {
animation: rotate 2s ease-out infinite;
border-top: 15px solid lightblue;
}
.spinner-sector-red {
animation: rotate 2.5s ease-in infinite;
border-top: 15px solid lightcoral;
}
.spinner-sector-green {
animation: rotate 1.5s ease-in-out infinite;
border-top: 15px solid lightgreen;
}
#keyframes rotate {
from {
transform: rotate(0);
}
to {
transform: rotate(360deg);
}
}
#keyframes loading-opacity {
0%,
100% {
opacity: 1;
}
25%,
75% {
opacity: 0.5;
}
50% {
opacity: 0.1;
}
}
<div class="spinner-container">
<div class="spinner">
<div class="spinner-text three-dots">Loading<span>.</span><span>.</span><span>.</span></div>
<div class="spinner-sector spinner-sector-red"></div>
<div class="spinner-sector spinner-sector-blue"></div>
<div class="spinner-sector spinner-sector-green"></div>
</div>
</div>
it's the first time I'm using css transitions/transformations and it's not working out that well.
I'm simply trying to translate from bottom to position each entry of a toggled menu, but I'm getting strange results.
When I run the code within my app it executes the transition only on the first item of the list instead of all items.
When I run the same code from jsfiddle the transition doesn't work at all on any item.
Please see my jsfiddle here
I've looked at the documentation, at so many different examples and at many other solutions for similar issues. I've tried them all, defying height, removing display, but nothing seems to make any difference
<header>
<a id="menu">
<i class="fas fa-bars"></i>
</a>
</header>
<nav class="nav nav-sm">
<ul class="nav__list">
<li class="nav__item">ABOUT</li>
<li class="nav__item">SKILLS</li>
<li class="nav__item">WORKS</li>
</ul>
</nav>
header {
width: 100%;
z-index: 3;
display: flex;
align-items: center;
justify-content: right;
background-color: #68c7c1;
min-height: 56px;
transition: min-height 0.3s;
}
header #menu {
margin-left: auto;
margin-right:10px;
color: #eceeef;
font-size: 2em;
}
.nav {
width: 100%;
height: auto;
position: absolute;
z-index: 2;
display: flex;
flex-wrap: wrap;
background-color: #68c7c1;
}
.nav-sm, .nav-lg { display: none; }
.nav-sm.open {
display: flex;
flex-wrap: wrap;
align-items: center;
height: calc(100% - 56px);
margin-top: -2px;
}
.nav__list, .nav__item { width: 100%; }
.nav__list {
display: flex;
flex-wrap: wrap;
}
.nav__item {
height:50px;
display: flex;
flex-wrap: nowrap;
justify-content: center;
}
.nav__item a {
text-decoration: none;
text-align: center;
font-size: 1.2em;
color: #eceeef;
}
.nav-sm .nav__list .nav__item {
color: red;
transition: -transform 3s ease-in-out;
-moz-transition: -moz-transform 3s ease-in-out;
-webkit-transition: -webkit-transform 3s ease-in-out;
}
.nav-sm.open .nav__item {
padding-bottom: 80px;
font-size: 2em;
transform: translate(0,-50px);
-moz-transform: translate(0,-50px);
-webkit-transform: translate(0,-50px);
}
An example of what I'm trying to achieve is something similar to the menu of this portfolio.
What are you exactly trying to do ? animation ? transition when clicked ?
here is an example of how to write animation via css :
div {
width: 100px;
height: 100px;
background-color: red;
animation-name: example;
animation-duration: 4s;
}
/* Standard syntax */
#keyframes example {
from {background-color: red;}
to {background-color: yellow;}
}
The way they did it in the example you provided is with js with some animation library, if you'd inspect their code you can see it happening.
To achieve this animation we'll have to make use of the delay property either way using animation or transition and you will have to add a delay on every item, so when you add a new item to the menu you'll have to add a delay to that item, we can automate this using js
Here's a demo using transition, the timing function, delay and the duration will need extra care, i'll leave that you to adjust to your desired end result.
var menu = document.querySelector("#menu");
var nav = document.querySelector(".nav-sm");
function openMenu(e) {
nav.classList.toggle("open");
e.stopPropagation();
};
function closeMenu(e) {
nav.classList.remove("open");
};
menu.addEventListener("click", openMenu);
#menu {
font-size: 2rem;
margin: 30px;
display: flex;
flex-direction: column;
align-items: flex-end;
}
ul {
border: 1px solid;
list-style: none;
padding: 10px;
margin: 30px;
}
li {
opacity: 0;
transform: translateY(5px);
margin: 20px 0;
text-align: center;
}
a {
text-decoration: none;
padding: 5px 30px;
background: dodgerblue;
color: white;
}
.open li:nth-child(1) {
transition: all .4s linear;
}
.open li:nth-child(2) {
transition: all .4s .2s linear;
}
.open li:nth-child(3) {
transition: all .4s .4s linear;
}
.open li {
opacity: 1;
transform: translateY(0px);
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css">
<div id="menu">
<i class="fas fa-bars"></i>
</div>
<ul class="nav-sm">
<li>ABOUT</li>
<li>SKILLS</li>
<li>WORKS</li>
</ul>
So, I managed to achieve what I wanted by mixing both suggestions :)
Please see the result in this jsfiddle.
The reason why the transition wasn't working it's because I'm using display:none on the .nav. This problem is resolved by using animation instead and applying a delay on each list element.
Thank you for both answers!
header {
width: 100%;
z-index: 3;
display: flex;
align-items: center;
justify-content: right;
background-color: #68c7c1;
min-height: 56px;
transition: min-height 0.3s;
}
header #menu {
margin-left: auto;
margin-right:10px;
color: #eceeef;
font-size: 2em;
}
.nav {
width: 100%;
height: auto;
z-index: 2;
display: flex;
flex-wrap: wrap;
background-color: #68c7c1;
}
.nav-sm, .nav-lg { display: none; }
.nav-sm.open {
display: flex;
flex-wrap: wrap;
align-items: center;
height: calc(100% - 56px);
margin-top: -2px;
}
.nav__list, .nav__item { width: 100%; }
.nav__list {
display: flex;
flex-wrap: wrap;
}
.nav__item {
height:50px;
display: flex;
flex-wrap: nowrap;
justify-content: center;
}
.nav__item a {
text-decoration: none;
text-align: center;
font-size: 1.2em;
color: #eceeef;
}
.nav-sm.open {
-webkit-animation: slide-down .3s linear;
-moz-animation: slide-down .3s linear;
}
.nav-sm.open .nav__item{
padding-bottom: 80px;
font-size: 2em;
}
.nav-sm.open .nav__item:nth-child(1) {
-webkit-animation: slide-down .3s .1s linear;
-moz-animation: slide-down .3s .1s linear;
}
.nav-sm.open .nav__item:nth-child(2) {
-webkit-animation: slide-down .3s .2s linear;
-moz-animation: slide-down .3s .2s linear;
}
.nav-sm.open .nav__item:nth-child(3) {
-webkit-animation: slide-down .3s .3s linear;
-moz-animation: slide-down .3s .3s linear;
}
#-webkit-keyframes slide-down {
0% { opacity: 0; -webkit-transform: translateY(-100%); }
100% { opacity: 1; -webkit-transform: translateY(0%); }
}
#-moz-keyframes slide-down {
0% { opacity: 0; -moz-transform: translateY(-100%); }
100% { opacity: 1; -moz-transform: translateY(0%); }
}
I am trying to typewrite 2 lines in CSS. My problem is that both lines are being written at the same time. I tried to use the animation-delay property but it does not work properly.
How can I type out the first line then type out the second line?
/*-----------------------LINE 1-----------------------*/
.line-1{
font-family: monospace;
position: relative;
top: 30%;
left: 15%;
width: 24em;
margin: 0 auto;
font-size: 250%;
text-align: left;
white-space: nowrap;
overflow: hidden;
transform: translateY(-50%);
}
/* Animation */
.anim-typewriter{
animation: typewriter 4s steps(44) 1s 1 normal both,
blinkTextCursor 500ms steps(44) infinite normal;
}
#keyframes typewriter{
from{width: 0;}
to{width: 9.5em;}
}
#keyframes blinkTextCursor{
from{border-right-color: rgba(255,255,255,.75);}
to{border-right-color: transparent;}
}
/*-----------------------LINE 2-----------------------*/
/* Animation */
.anim-typewriter2{
animation: typewriter 4s steps(44) 1s 1 normal both,
blinkTextCursor 500ms steps(44) infinite normal;
animation-delay: 4s;
}
#keyframes typewriter{
from{width: 0;}
to{width: 15em;}
}
#keyframes blinkTextCursor{
from{border-right-color: rgba(255,255,255,.75);}
to{border-right-color: transparent;}
}
<p class="line-1 anim-typewriter">Hi, I'm Mohanad,</p>
<p class="line-2 anim-typewriter2">I do cool computer stuff.</p>
/*-----------------------LINE 1-----------------------*/
.line-1, .line-2 {
font-family: monospace;
position: relative;
top: 30%;
left: 15%;
width: 24em;
margin: 0 auto;
font-size: 250%;
text-align: left;
white-space: nowrap;
overflow: hidden;
transform: translateY(-50%);
}
/* Animation */
.anim-typewriter {
animation: typewriter1 4s steps(44) 1s 1 normal both,
blinkTextCursor1 500ms steps(44) infinite normal;
}
#keyframes typewriter1 {
from {
width: 0;
}
to{
width: 9.5em;
}
}
#keyframes blinkTextCursor1 {
from {
border-right-color: rgba(255,255,255,.75);
}
to {
border-right-color: transparent;
}
}
/*-----------------------LINE 2-----------------------*/
/* Animation */
.anim-typewriter2{
animation: typewriter2 4s steps(44) 1s 1 normal both,
blinkTextCursor2 500ms steps(44) infinite normal;
animation-delay: 5s;
}
#keyframes typewriter2 {
from {
width: 0;
}
to {
width: 15em;
}
}
#keyframes blinkTextCursor2 {
from {
border-right-color: rgba(255,255,255,.75);
}
to {
border-right-color: transparent;
}
}
<p class="line-1 anim-typewriter">Hi, I'm Mohanad,</p>
<p class="line-2 anim-typewriter2">I do cool computer stuff.</p>
I guess this is what you're looking for. My guess is that you defined 2 animatations with the same name and therefor you overwrite them. Also you needed to specify properties from .line-1 to .line-2
I have created simple progress-bar alike animation using keyframes. Seems to not work on windows safari 5.1.7, also on mac safari (can't provide version). Here is fiddle i created http://jsfiddle.net/26tgnrff/4/ . Been digging around for some while, but cant find solution.
Thanks.
html:
<div class="content">
<h3>Animation demo</h3>
<ul id="skill">
<li><span class="animated expand y2003 green"></span>
</li>
<li><span class="animated expand y2006 purple"></span>
</li>
<li><span class="animated expand y2008 green"></span>
</li>
<li><span class="animated expand y2011 purple"></span>
</li>
<li><span class="animated expand y2014 green"></span>
</li>
</ul>
</div>
css:
.expand {
height: 25px;
margin: 2px 0;
position: absolute;
}
.expand.green {
background: #8DD005;
box-shadow: 0px 0px 7px 0px #86a624;
}
.expand.purple {
background: #5a3266;
box-shadow: 0px 0px 7px 0px #5a3266;
}
.animated.y2003 {
width: 15%;
-moz-animation: html5 2s ease-out;
-webkit-animation: html5 2s ease-out;
animation: html5 2s ease-out;
}
.animated.y2006 {
width: 52.5%;
-moz-animation: css3 2s ease-out;
-webkit-animation: css3 2s ease-out;
animation: css3 2s ease-out;
}
.animated.y2008 {
width: 84.7%;
-moz-animation: jquery 2s ease-out;
-webkit-animation: jquery 2s ease-out;
animation: jquery 2s ease-out;
}
.animated.y2011 {
width: 77.5%;
-moz-animation: photoshop 2s ease-out;
-webkit-animation: photoshop 2s ease-out;
animation: photoshop 2s ease-out;
}
.animated.y2014 {
width: 100%;
-moz-animation: dreamweaver 2s ease-out;
-webkit-animation: dreamweaver 2s ease-out;
animation: dreamweaver 2s ease-out;
}
#-moz-keyframes html5 {
from {
width: 5px;
}
to {
width: 15%;
}
}
#-moz-keyframes css3 {
from {
width: 5px;
}
to {
width: 52.5%;
}
}
#-moz-keyframes jquery {
from {
width: 5px;
}
to {
width: 84.7%;
}
}
#-moz-keyframes photoshop {
from {
width: 5px;
}
to {
width: 77.5%;
}
}
#-moz-keyframes dreamweaver {
from {
width: 5px;
}
to {
width: 100%;
}
}
#-webkit-keyframes'html5' {
from {
width: 5px;
}
to {
width: 15%;
}
}
#-webkit-keyframes'css3' {
from {
width: 5px;
}
to {
width: 52.5%;
}
}
#-webkit-keyframes'jquery' {
from {
width: 5px;
}
to {
width: 84.7%;
}
}
#-webkit-keyframes'photoshop' {
from {
width: 5px;
}
to {
width: 77.5%;
}
}
#-webkit-keyframes'dreamweaver' {
from {
width: 5px;
}
to {
width: 100%;
}
}
You have extra semicolons at the end of your keyframes - should be e.g.
#-webkit-keyframes'photoshop' {
from {
width: 5px;
}
to {
width: 77.5%;
}
/* no semicolon here */
}
Updated fiddle http://jsfiddle.net/26tgnrff/8/
Further, on Safari 5 you can't animate width to a percentage value. If you use px values instead of % the animation will work.
However you can achieve a similar effect with scaling instead, and then you don't need the actual values in the keyframes:
#-webkit-keyframes'html5' {
from {
-webkit-transform-origin: 0 0;
-webkit-transform: scale(0,1);
}
to {
-webkit-transform-origin: 0 0;
-webkit-transform: scale(1,1);
}
}
Updated fiddle (only animating the first bar as an example) http://jsfiddle.net/26tgnrff/9/
My goal is to create a dropdown that fades in every time its parent element is moused over.
And, I want to use the CSS #keyframe property to control the opacity.
See the below example. It works in IE and Chrome as expected (fade-in happens on every mouse over). But, in FireFox, the fade-in happens only on the first mouse over. How can I get the fade-in to happen every time in FireFox?
CodePen showing example:
http://codepen.io/anon/pen/IEBgb
(notice the green "Baz" text fades in)
HTML:
<div class="foo">Foo
<div class="bar">
<div class="baz">
Baz
</div>
</div>
</div>
CSS:
#-webkit-keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
#-moz-keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
#keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.foo {
cursor: pointer;
background: #333;
color: #ededed;
height: 50px;
line-height: 50px;
position: relative;
text-align: center;
width: 200px;
font-size: 30px;
}
.bar {
width: 200px;
position: absolute;
top: 52px;
background: gray;
display: none;
padding: 20px 0;
}
.foo:hover .bar {
display: block;
}
.baz {
font-size: 50px;
color: green;
visibility: visible;
opacity: 1;
-webkit-animation: fadeIn 2s;
-moz-animation: fadeIn 2s;
-o-animation: fadeIn 2s;
animation: fadeIn 2s;
}
It can be done, but you will have to adjust a few things:
Working Example
#-webkit-keyframes fadeIn {
0% {
color: rgba(0, 128, 0, 0); /* transparent text color */
opacity: 0;
}
50% {
color: rgba(0, 128, 0, 0); /* transparent text color */
opacity:1;
}
100% {
color: rgba(0, 128, 0, 1); /* fade in text color */
opacity: 1;
}
}
#keyframes fadeIn {
0% {
color: rgba(0, 128, 0, 0);
opacity: 0;
}
50% {
color: rgba(0, 128, 0, 0);
opacity:1;
}
100% {
color: rgba(0, 128, 0, 1);
opacity: 1;
}
}
.foo {
cursor: pointer;
background: #333;
color: #ededed;
height: 50px;
line-height: 50px;
position: relative;
text-align: center;
width: 200px;
font-size: 30px;
}
.bar {
display:none;
width: 200px;
position: absolute;
top: 50px;
background: gray;
padding: 20px 0;
}
.baz {
font-size: 50px;
}
.foo:hover .bar {
display: block;
-webkit-animation: fadeIn 2s both; /* attach the animation to bar rather than baz */
animation: fadeIn 2s both;
}
Or if you're looking to fade in and fade out you could try something like this:
Working Example 2
Note that the second method uses pointer-events:none/auto so it may have compatibility issues in older browsers. Also seeing the fadeOut animation when the page first loads may be a problem.