posted on:March 27, 2008
Pure CSS Animated Progress Bar
Here’s a simple demonstration of how you can create animated progress bar using pure css. The trick is very simple. We need 3 elements, one container and 2 nested elements.
Take a look at the demo
| Download zip file
The Concept
We’ll put a cool background image in the container and define fixed width and height. First child (SPAN) will act as a progress bar. We’ll absolutely position second child (EM) above the progress bar and shift it to the left to a desired value. EM has the same background as the container so it gives an effect of progress bar stopping at certain percentage.
Markup
To keep it as meaningful as possible I used definition list (DL) to list for several values. For single progress bar you can use any element you want. I love paragraphs so I used P in my example.
<dd> <span><em style="left:100px">50%</em></span> </dd>
I decided to use inline styles for left EM placement. It is more convenient to write both values at the same place at once.
Animation
How is it done? Using animated gif of course. Remember those? SPAN has a 200px wide background gif that animates from "zero" to 200px. No matter what percentage we use it goes all the way and stops. Effect of stopping at certain percentage is done with EM as I mentioned earlier.
EM placement
In my example I use 200 pixels wide progress bar. EM element is also 200px wide. So each percentage is 2px wide. If we want to accurately shift the EM we need to multiply percentages with 2.
i.e. 50% will mean 100px left offset, 24% will mean 48px offset, 75% – 150px etc. You get the picture. 🙂
Enjoyed the article?
Then don't miss our next one! Subscribe to our RSS feed or share it with your friends.
Share on FacebookTweet thisDeliciousStumbleUpon RedditSubscribe
Comments (55 Comments)
Sorry, the comment form is closed at this time.
Catar4x
March 27, 2008
henri - blog webdesign
March 27, 2008
Yves
March 27, 2008
Peter
March 28, 2008
cssglobe
March 28, 2008
fwolf
March 28, 2008
GUESS
March 28, 2008
BTM
March 30, 2008
cssglobe
March 30, 2008
fedmich
March 30, 2008
Mauro De Giorgi
March 31, 2008
Markavian
March 31, 2008
Simon Gow
March 31, 2008
Quevin
March 31, 2008
Muralikrishna
April 2, 2008
Carlos Fernando Benitez Zapata
April 2, 2008
Carlos Fernando Benitez Zapata
April 2, 2008
vincent Voyer
April 3, 2008
cssglobe
April 3, 2008
Quoka
April 4, 2008
Quoka
April 4, 2008
Quoka
April 4, 2008
Rafael Masoni
April 5, 2008
gwinn
April 7, 2008
Micael
April 9, 2008
Herbalife
April 11, 2008
Jay
April 12, 2008
Tanguy
April 16, 2008
Max
April 20, 2008
David Blanchet
April 24, 2008
cssglobe
April 25, 2008
Nima Fatemi
May 3, 2008
John Faulds
May 5, 2008
Seb
May 9, 2008
Arun
May 14, 2008
Jack Neary
May 16, 2008
sotec software
May 21, 2008
Jeremy
May 22, 2008
Stoik
May 24, 2008
cam filmi
June 1, 2008
Jon
June 4, 2008
niladri
June 20, 2008
Berthold
August 17, 2008
Herbalife
August 22, 2008
Douglas
September 12, 2008
tibolan
November 26, 2008
pinksoler
December 9, 2008
sura1
December 10, 2008
HerbalDistribuidor
December 12, 2008
blues
January 8, 2009
vexorian
February 22, 2009
rduke15
March 11, 2009
Hassan
March 15, 2009
Nathan
April 5, 2009
Craig Beaumont
April 15, 2009