I am having a progess bar which should become filled up by 50% width.
This is my current html and css for the progress bar.
HTML:
<div id="ProgressBar">
<div id="Progress"></div>
</div>
CSS:
#ProgressBar {
width: 100%;
height: 30px;
border: 1px solid black;
border-radius: 7px;
padding: 4px;
}
#Progress {
width: 10%;
background-color: #4A90E2;
height: 100%;
border-top-left-radius: 7px;
border-bottom-left-radius: 7px;
border-color: #4A90E2;
-webkit-transition: width 2s; /* For Safari 3.1 to 6.0 */
transition: width 2s;
}
#Progress:hover {
width: 50%;
}
As you can see the transition is starting after a hover over the progress. My goal is to have this transaition starting directly after the page loads. I know there are some examples in the internet but they are all having fade-in effects only and I can't figure it out.
I appreciate your help.
Here my fiddle:
https://jsfiddle.net/Anokrize/ssL9fjy9/
(I would like to avoid any javascript or jquery, if that is possible)
How about doing it with keyframes, like this:
#ProgressBar {
width: 100%;
height: 30px;
border: 1px solid black;
border-radius: 7px;
padding: 4px;
}
#Progress {
width: 50%;
background-color: #4A90E2;
height: 100%;
border-top-left-radius: 7px;
border-bottom-left-radius: 7px;
border-color: #4A90E2;
animation-name: progressBar;
animation-iteration-count: 1;
animation-duration: 2s;
}
#keyframes progressBar {
0% {
width: 10%;
}
100% {
width: 50%;
}
}
<div id="ProgressBar">
<div id="Progress"></div>
</div>
A straight forward way of getting this done is through jquery:
$(window).load(function() {
$("#Progress").css("width", "50%");
});
Usually you'd want something feeding a progress bar so it's actually showing progress... but if you just want it to start on load, you can use the animation property with keyframes.
#ProgressBar {
width: 100%;
height: 30px;
border: 1px solid black;
border-radius: 7px;
padding: 4px;
}
#Progress {
width: 10%;
background-color: #4A90E2;
height: 100%;
border-top-left-radius: 7px;
border-bottom-left-radius: 7px;
border-color: #4A90E2;
animation: progress 1s ease-out forwards;
}
#keyframes progress {
from { width: 10%; }
to { width: 50%; }
}
Related
I have a question about CSS. I've coded an animation to rotate on hover. Now when I hover on it, it's glitching really much. It just begins the rotation again and again. Can someone please help. Code is here:
#text {
width: 300px;
height: 150px;
background-color: lightgray;
border-left: 0px groove;
border-top: 0px groove;
border-radius: 10px;
margin: auto;
padding: 5px;
transition: all 0.3s ease-in;
}
#text:hover {
border-left: 10px groove;
border-top: 10px groove;
background-color: lightskyblue;
transform: rotateY(360deg);
}
#text::after {
content: "Hover me";
font-size: 30px;
margin-left: 100px;
color: black;
}
#text:hover::after {
content: "If you want to know how to get started as a web developer, take a look at my youtube channel";
margin: 0;
font-size: 20px;
}
<div id="text">
</div>
As Paulie_D correctly stated, your :hover triggers the animation, but terminates the animation when your mouse leaves the #text element. So it resets.
There are multiple ways to fix this like this example to make a new container element that doesn't move but only triggers the animation.
.text {
width: 100%;
height: 150px;
background-color: lightgray;
border-left: 0px groove;
border-top: 0px groove;
border-radius: 10px;
padding: 5px;
transition: all 0.3s ease-in;
margin-bottom: 20px;
}
.animated-card {
margin: auto;
width: 300px;
}
.animated-card:hover > .text {
transform: rotateY(360deg);
}
.text:hover {
border-left: 10px groove;
border-top: 10px groove;
background-color: lightskyblue;
}
.text::after {
content: "Hover me";
font-size: 30px;
margin-left: 100px;
color: black;
}
.text:hover::after {
content: "If you want to know how to get started as a web developer, take a look at my youtube channel";
margin: 0;
font-size: 20px;
}
<div class="animated-card">
<div id="text"></div>
</div>
<div class="animated-card">
<div class="text"></div>
</div>
<div class="animated-card">
<div class="text"></div>
</div>
<div class="animated-card">
<div class="text"></div>
</div>
I've been coding a very simple "Traffic Light" program and have run into a problem where it doesn't run after the first #keyframes section completes correctly. From my own research online I'm guessing that I would need a transition(?) so that when the first #keyframes is complete, the next one would be run. However my inexperience with this I'm not sure if its whats required here. Essentially is there a "trigger" I'm missing or is it just something obvious I've left out?
Please excuse the rough code. Its does work as I described above
body {
background-color: #4d4d00
}
.container {
display: flex;
justify-content: center;
align-items: center;
}
#red {
position: absolute;
left: 50px;
text-align: center;
padding: 30px;
background-color: #e60000;
margin: 10px auto;
width: 50px;
height: 50px;
border-radius: 200px;
animation: red 4s 1s 3 linear;
}
#amber {
position: absolute;
left: 1px;
text-align: center;
padding: 30px;
background-color: #ff3300;
margin: 10px auto;
width: 50px;
height: 50px;
border-radius: 200px;
animation: amber 4s 1s 3 linear;
}
#green {
position: absolute;
left: 1px;
text-align: center;
padding: 30px;
background-color: #009933;
margin: 10px auto;
width: 50px;
height: 50px;
border-radius: 200px;
animation: green 4s 1s 3 linear;
}
#keyframes red {
from {
background-color: #e60000;
}
to {
background-color: #000000;
}
#keyframes amber {
from {
background-color: #ff3300;
}
to {
background-color: #000000;
}
#keyframes green {
from {
background-color: #009933;
}
to {
background-color: #000000;
}
}
<div class="container">
<div class="row">
<div id="red">
<br>
<br>
<div id="amber">
<br>
<br>
</div>
</div>
</div>
</div>
you may use animation-delay.
here is a short/minimal code example.
.red {
background: red;
}
.orange {
background: orange
}
.green {
background: lime;
}
/* layout */
div {
display: flex;
height: 150px;
width: 50px;
flex-direction: column;
border-radius: 1em;
background: #555;
margin: 1em;
}
b {
flex: 1;
margin: 5px;
border-radius: 50%;
animation: fade 9s steps(2, end) infinite;
box-shadow: 0 0 5px white
}
/* animation */
#keyframes fade {
66%,
100% {
background: gray;
box-shadow: 0 0
}
}
.red {
animation-delay: -12s
}
.orange {
animation-delay: -6s;
}
<div class=trafficLights>
<b class=red></b>
<b class=orange></b>
<b class=green></b>
</div>
here is a codepen to play with : https://codepen.io/gc-nomade/pen/YVWeQq
You have two way to do this
1) is use animation-delay and set an higher delay to elements you would like to animate after.
animation-delay: 1s;
-webkit-animation-delay:1s;
2) trigger an element.addClass("animatedClass"); with the end of a css animation using animationonend jquery function.
$(".animatedElement").one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function(event) {
$(".animatedElement").addClass("newAnimatedClass");
});
I'm trying to let the animation pause in the last keyframe, so if the lines are at 50% of the page they will stay there and not go back to the first keyframe.
Also is css the best way to do this or is there a easier way to solve this?
The css:
body, html {
height: 100%;
text-align: center;
margin: 0;
}
body {
background-color: royalblue;
}
.loader {
display: inline-block;
width: 30px;
height: 30px;
position: relative;
border: 4px solid white;
top: 50%;
animation: loader 4s ease;
}
.line1 {
position: relative;
display: inline-block;
top: 0;
width: 5px;
height: 10px;
border: 2px solid #fff;
background-color: #fff;
left: 20%;
animation: lines 5s infinite ease;
}
.line2 {
position: relative;
display: inline-block;
top: 0;
width: 5px;
height: 10px;
border: 2px solid #fff;
background-color: #fff;
right: 20%;
animation: lines 5s infinite ease;
}
#keyframes lines {
0% { height: 10px; }
25% { height: 10px; }
50% { height: 50%; }
75% { height: 50%; }
100% { height: 50%;
-webkit-animation-play-state: paused; /* Chrome, Safari, Opera */
animation-play-state: paused; }
}
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Loader1 - by Thom</title>
<!-- Custom loading-thom -->
<link href="style.css" rel="stylesheet">
</head>
<body>
<span class="line1"></span>
<span class="line2"></span>
</body>
</html>
You could use animation-fill-mode property with forwards as value.
CSS
.line1{
position: relative;
display: inline-block;
top: 0;
width: 5px;
height: 10px;
border: 2px solid #fff;
background-color: #fff;
left: 20%;
animation: lines 5s forwards ease;
}
.line2{
position: relative;
display: inline-block;
top: 0;
width: 5px;
height: 10px;
border: 2px solid #fff;
background-color: #fff;
right: 20%;
animation: lines 5s forwards ease;
}
DEMO HERE
What you are looking for is something called animation-fill. You can read more about it here: http://www.w3schools.com/cssref/css3_pr_animation-fill-mode.asp
So essentially:
.line1,
.line2 {
animation-fill: forwards;
}
Also make sure that the animation-fill is declared after the animation rule.
SOLUTION 1:
Your can change animation-fill to forward
SOLUTION 2:
use jquery
<script>
$(document).ready(function(){
var half = $(document).height()/2;
setTimeout(function(){
$('.line1 , .line2').animate({height:half});
},1000);
});
In DEMO below, press Run in jsFiddle;
DEMO: https://jsfiddle.net/0andyke4/5/
I'm designing an animated progress bar to display ratings on my website. At the end of the bar, I want to display inside a circle the rating number (out of 10) corresponding to the final progress % of the bar. I want to have a responsive design.
My problem arises when dealing with a high progress %, such as 95%. The circle with the rating value is sent down to the next line. It is also the case when resizing my browser with a progress value such as 75%. With lower values, everything is fine. I tried to play around with negative margin-left and margin-right values for #ratingnumber, which seems to help a bit but still had trouble keeping the rating circle on the progress bar for really high progress %.
I'm looking for the CSS tweak to keep the rating circle on the progress bar for every rating cases.
jsfiddle for 95%: http://jsfiddle.net/4pzm98b0
jsfiddle for 50%: http://jsfiddle.net/z1wtqebj/
<div id="progressbar">
<div id="progress"></div>
<div id="ratingnumber">
9.5
</div>
</div>
body {
background-color: #aaa;
padding: 40px;
}
#progressbar {
width: 100%;
height: 20px;
background-color: white;
-moz-border-radius: 25px;
-webkit-border-radius: 25px;
border-radius: 25px;
padding: 3px;
border: 3px solid #666666;
clear: both;
}
#progress {
background: green;
height: 20px;
width: 0%;
max-width: 100%;
float: left;
-webkit-animation: progress 2s 1 forwards;
-moz-animation: progress 2s 1 forwards;
-ms-animation: progress 2s 1 forwards;
animation: progress 2s 1 forwards;
-webkit-border-top-right-radius: 8px;
-webkit-border-bottom-right-radius: 8px;
-moz-border-radius-topright: 8px;
-moz-border-radius-bottomright: 8px;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
-webkit-border-top-left-radius: 20px;
-webkit-border-bottom-left-radius: 20px;
-moz-border-radius-topleft: 20px;
-moz-border-radius-bottomleft: 20px;
border-top-left-radius: 20px;
border-bottom-left-radius: 20px;
}
#ratingnumber{
border: 4px solid green;
background: white;
padding: 10px;
float: left;
font-size: 28px;
font-family: 'Roboto Condensed', sans-serif;
font-weight: bold;
border-radius: 50%;
position: relative;
left: -30px;
top: -24px;
}
#-webkit-keyframes progress {
from { }
to { width: 95% }
}
#-moz-keyframes progress {
from { }
to { width: 95% }
}
#-ms-keyframes progress {
from { }
to { width: 95% }
}
#keyframes progress {
from { }
to { width: 95% }
}
Add white-space: nowrap to the parent element, #progressbar. Then remove float: left from the children elements, and change the display to inline-block in order for them to respect the white-space property on the parent. Set vertical-align: top on the children in order to fix the vertical alignment.
Updated Example
#progressbar {
white-space: nowrap;
}
#ratingnumber, #progress {
display: inline-block;
vertical-align: top;
}
The positioning on the #ratingnumber element also needs to be changed to:
#ratingnumber {
position: relative;
top: -20px;
}
Is there a way to get a loading icon to show when a button/link is clicked, with just CSS/HTML?
I'm using FontAwesome so I figured I could use their classes to spin a loading icon, but I can't find a way to get it to spin after a specific action (mouseclick).
Basically this is all the code:
<i class="fa fa-circle-o-notch fa-spin"></i> Spin
The only way I could manage now was hiding it in background color.. but that doesn't seem very professional:
body {
background: none repeat scroll 0 0 #dcdcdc;
color: white;
}
.fa {
color: #dcdcdc;
}
a:active .fa {
color: red;
}
Any suggestions?
If an element that looks like a button is acceptable, you can do this with CSS as long as you don't need to support IE8. It works by using a label "for" a checkbox or radio as your button. Then, the :checked CSS pseudo class does the trick!
This example sets the background color of a div, but you can set whatever properties you need.
label {
display: inline-block;
background-color: #28529c;
color: white;
padding: 4px 8px;
}
#loading {
background-color: transparent;
width: 20px;
height: 20px;
}
#hidden-flag {
display: none;
}
#hidden-flag:checked ~ #loading {
background-color: green;
display: inline-block;
padding-left: 10px;
}
<input id="hidden-flag" type="radio">
<label for="hidden-flag">Button</label>
<div id="loading"></div>
Needs a bit of work, But as I'm off to beddy byes now I'm not carrying on with it, Up early tomorrow. Pure css sort of unfinished example. When the new page is loaded just bring in a new set of buttons to click.
#to_click:visited {
content:"";
display: block;
float: left;
position: relative;
margin: 40px 30px;
border-radius: 100px;
width: 20px;
height: 20px;
border: 5px solid #57E;
border-top-color: transparent;
border-bottom-color: transparent;
animation-name: rotateclock;
animation-duration: .75s;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
#to_click:before {
content: "";
display: block;
position: absolute;
top: 0;
left: 0;
border-radius: 100px;
width: 10px;
height: 10px;
border: 5px solid #57E;
border-left-color: transparent;
border-right-color: transparent;
}
#to_click:after {
content: "";
display: block;
position: absolute;
top: 5px;
left: 5px;
border-radius: 100px;
width: 0px;
height: 0px;
border: 5px solid #57E;
border-top-color: transparent;
border-bottom-color: transparent;
}
#keyframes rotateclock {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
Click Me