Placed in: Home arrow Programming arrow CSS arrow Wicked CSS3 3d bar chart

Cialis Online

Wicked CSS3 3d bar chart

More and more CSS3 articles are popping up on Marcofolio and all across the web. Although CSS3 is just future talk (since not all browsers support it yet), it's pretty cool to get a sneak peak on what the future will hold for us.

While browsing the web, I came across a pretty cool 3d bar chart created with Flash. I was wondering if I could recreate the same neat effect using pure CSS3 and started working on this wicked CSS3 3d bar chart. Check out the example to see that (almost) no images were used to create this wicked effect.

CSS3 bar chart

The only images that are used in this example, were taken from the Superpack icon pack and only show the Apple icons. Everything else you see in this demo, is created using pure CSS3.

Demo CSS3 3d bar chart   Download CSS3 3d bar chart

This example only works in the latest versions of Firefox, Chrome, Safari and Opera. Since Internet Explorer still doesn't fully support CSS3, this example looks a bit weird in IE. So, for now, this is just another sneak peak into the future. Let's check out how you can create this!

Video

Here's an example of the page showed in the latest version of Firefox (3.6). It shows all the effects as they should show (rounded corners, gradients, shadow, rgba etc.)

I guess I warmed you up on how you could create something like this yourself, haven't I? Let's take a look under the hood.

HTML

As usual, we want to keep our HTML clean and tidy. This is what we're going to use:

 
<ul id="bar">
   <li id="iphone">
      <div class="top">
         <img src="images/iphone.png" alt="iPhone" />
      </div>
      <div class="bottom">
         <div class="infobox">
            <h3>iPhone</h3>
            <p>80,1</p>
         </div>
      </div>
   </li>
   <!-- More bar chart items -->
</ul>

As you can see, we're simply using an unordered list that contains several items (the bars). Each bar contains from two segments: The Top and the Bottom. We'll use the magic of CSS to style the top (which also contains the image) to an ellipse (top of the bar). The bottom (the bar body), that contains the info of the bar, will be styled to have a pretty rounded border too.

The HTML itself is pretty boring (which it should be!), and we'll let CSS(3) do it's magic to make the page look beautiful.

CSS

Before we start digging through the CSS, I would like to note that I only discuss the most interesting/important stuff in this tutorial. All the CSS needed to create the exact same page can be found in the download and/or demo.

First, we'll need to clear some default list stuff from the CSS. This prevents the "dots" you would normally see on lists.

 
#bar { list-style:none; }

That took care of that. Now, let's get ready to style the top of each bar. Take note these are the generic classes applied to each bar; We'll discuss the specific things later.

 
#bar li div.top { background-color:rgba(140,172,176,0.5); position:relative;
   width:100px; height:40px; -moz-border-radius: 100px/40px; -webkit-border-radius: 100px 40px; border-radius: 100px/40px; }
#bar li div.top img { display:none; }

Now this is where it gets interesting. We apply a half-transparent background-color using rgba (last value is opacity). We need this transparency since we need to stack all the bars on top of each other and still see the color that is underneath. We also set the position to relative, since we need to specify the z-index later.

We set the top box to a specific size (100 x 40). We than use the CSS3 border-radius property to create rounded corners. Because we pass on two values, we're able to create an ellipse (which is what we need). Take note of the different -moz- and -webkit- implementations. I don't know why this is different (one uses a space, the other one a dash).

The image of the top has been hidden with display set to none. We'll show it on hovering the item. We now created an ellipse for the top of the bar. Now, let's move on to the body (bottom) of the bar.

 
#bar li div.bottom { background-color:rgba(184,203,205,0.5); margin-top:-40px; position:relative;
   width:100px; -moz-border-radius: 100px/40px; -webkit-border-radius: 100px 40px; border-radius: 100px/40px; }

Just like with the div.top, we apply a half-transparent background-color using rgba. We shift the bottom a little bit up (margin-top:-40px;) to place it directly under the top. We apply only the width (height will be set differently for each item) and we apply the same kind of rounded corners to match the ellipse from the top.

The last generic CSS thing we now need, is to display the image once we're hovering. One line of code will deal with that:

 
#bar li:hover div.top img { display:inline; }

That's all the CSS we need for the generic things. Now we need to move on to some specific values, that's why we have some separate id in the HTML (like id="iphone">).

 
#iphone div.top { z-index:99; }
#iphone div.bottom { z-index:98; height:150px; }
#iphone:hover div.top { z-index:999; background-color:#1f81ac; }
#iphone:hover div.bottom { z-index:998; background-color:#1a6c90;
   background:-moz-linear-gradient(-90deg, #1a6c90, #14506b); background:-webkit-gradient(linear, 0 top, 0 bottom, from(#1a6c90), to(#14506b)); }

First, we apply the z-index of the top and the bottom elements. The top always have to be greater than the bottom to stick on front, and the next items (macbook etc.) have to be smaller. This way, we can control what is placed in front and what not. As you can see, when we :hover the item, we bring the elements completely to the front (since we need to overrule the z-index of the next bar).

A specific height is set for the bottom, depending on how big you want your chart to be. We give the top a fixed background-color when hovering (no transparancy) and the bottom gets a fancy gradient (take note of the once again different -moz- and -webkit- implementations).

Almost done with our 3d bar chart: I've added a couple of minor things to make it complete.

 
/* First top should have a different colour */
#bar li:first-child div.top { background-color:rgba(186,211,215,0.5); }
 
/* Last bottom should have a shadow */
#bar li:last-child div.bottom { -moz-box-shadow: 0 10px 10px hsla(0,0%,0%,.2); -webkit-box-shadow: 0 100px 30px hsla(0,0%,0%,.2); box-shadow: 0 100px 30px hsla(0,0%,0%,.2); }

The first .top should have a different colour, since there's nothing on it's background. Since we're using transparancy, we slightly need to change it (using :first-child pseudo selector) to set it to the correct value. Just for extra fanciness, we apply a shadow at the bottom using :last-child pseudo selector. Also, take note of the use of the hsla colour property here; it was just easy to use.

Well, that's all it takes to create this fancy looking 3d CSS3 bar chart. Take a look in my CSS how to display the .infobox elements the way they're shown in the demo and you're ready to go.

Conclusion and Download

Although not all browsers support this effect, it's pretty cool to see what CSS3 can achieve. One small downside of this script, is that the bottom bar can't be smaller than the height of the top bar. Other than that, I think it's a really wicked effect I would love to see on more websites.

Demo CSS3 3d bar chart   Download CSS3 3d bar chart

What do you think of this technique? What else would you like to see in this CSS? Feel free to share your thoughts!


Tags:  bar chart 3d css3

Interested in this topic? You might enjoy another article I've written called

Did you like this article? Subscribe to my feed or email to keep updated on new articles.

Spread the word and submit to:
Digg!Reddit!Del.icio.us!Facebook!StumbleUpon!
Comments
Add NewSearchRSS
Lars - Really impressive!   2010-05-24 23:56:16
Gravatar image Great idea, cool tutorial. I like your creativeness, keep up the good work.
ELQ - Sweet!   2010-05-25 00:03:54
Gravatar image That rocks, nice tutorial.
Jireck   2010-05-25 08:39:52
Gravatar image Really Great ... like always
Joddy Street - Sweet   2010-05-25 08:42:54
Gravatar image bar graph, gr8 tute...
Really liked the hover over part
Janko   2010-05-25 09:40:48
Gravatar image Marco this is awesome, I really like the effect!
Beben - Prodigy of Head   2010-05-25 12:10:52
Gravatar image hihihihi... :lol:
this is cool :whistle: thanks... :)
Anonymous   2010-05-25 14:26:24
Gravatar image
Quote:
Although CSS3 is just future talk (since not all browsers support it yet),
Future talk? I'll stop the presses right now since we've been using a lot of CSS3 in our work for quite some time now! Glad you informed us. :rollseyes:
Marco - Don't!   2010-05-25 20:12:59
Gravatar image I think you should use CSS3 as an "extra" design feature, as long as you have a supporting CSS solution as well (so no people with older browsers will miss the effect, like rounded corners).
Catherine Azzarello   2010-05-25 17:23:49
Gravatar image Wicked Cool is right!
Marco - Thanks a lot!   2010-05-25 20:11:59
Gravatar image @Lars, @ELQ, @Jireck, @Joddy, @Janko, @Beben, @Catherine
Thanks a lot for those kind words/taking the time to leave a comment folks, really appreciate it! I'm really glad you liked the script and it opened up some new doors for you :) .
Paul Irish - moar css transitions   2010-05-25 23:29:02
Gravatar image Could definitely use some transitions. :)
Marco - Working on that!   2010-05-26 07:58:35
Gravatar image Hi Paul!

Don't worry - I was already working on that one ;) ! Will take this idea and use some CSS3 animations to make it even more amazing.

Stay tuned!
rohit - Tutorials   2010-05-28 08:17:21
Gravatar image Nice Tutorials,
Brilliant works and great css ,I think its very useful for me.. thanks
visit : news.ewebtutorial.com
Jordan Walker - Jordan Walker   2010-05-28 15:29:55
Gravatar image Excellent tutorial.
Rilwis - Nice   2010-05-29 00:19:03
Gravatar image Nice tutorial :) Thanks for sharing.
Prefabrik Yap - Prefabrik Yap   2010-06-11 14:08:49
Gravatar image Thank you for sharing has been nice knowing I'm constantly sharing
and keep track of your shares I would like to share my very nice and informative shares
iconshock - Great as usual   2010-06-16 18:57:39
Gravatar image Nice job marco, great as usual !!
sewa mobil di surabaya - good job   2010-06-19 07:54:26
Gravatar image i thank you for the tutorial and video above
:lol:
Dario - Thank you   2010-06-20 15:51:04
Gravatar image This is impressive!!!
Dipanjan Munshi   2010-06-26 13:21:06
Gravatar image :lol: Great Work :lol:
I never knew I can make an ellipse so easily with css
Keep posting such great articles
leonid - leonid   2010-07-09 13:00:49
Gravatar image very usefull lesson!!!
Bejamin Buttonyahu - Amazing project.   2011-06-24 07:13:09
Gravatar image Studio Max, Xara and some times illustrator with texture and coloring done in photoshop prefabrik and others completely designed using photoshop. Hope konteyner you like this collection thanks for including my tutorial too between those great picks. Adding one more kabin dimension to work really evolves possibilities!
Yass   2011-07-21 16:47:35
Gravatar image :lol: awesome. thanks for sharing!!!!
hirmani80 - WebHostingPad Reviews   2011-08-02 09:08:52
Gravatar image I had really like it very much for interesting info in this blog and the helpful info in this blog. I really love this info that to very satisfied by the info in this blog. It was really very great info in this website. This website is design is very great and the nice info in this blog. The website quality is very nice and the nice info in this blog. Thanks a lot for sharing the nice info in this blog
hirmani80 - WebHostingPad Reviews   2011-08-02 09:10:25
Gravatar image I am very much satisfied by the info in this blog and the useful info in this website. I was searching for some different info in this website and the great nice info in this blog. This is very much impressing with this info in this blog. I am very much thanking you for visiting the nice info in this blog and helpful info in this website. I had really like it very much for the info wise
PhotoshopWarrior - Hi   2011-09-18 17:55:07
Gravatar image Useful lesson, thanks
sewa mobil jakarta - great..   2011-09-23 16:01:26
Gravatar image great article ...
Mustafa Arslan - Seo   2012-01-20 09:28:42
Gravatar image Although this is not a konteyner step-by-step tutorial, for those interested in the JavaScript/jQuery used, I
Read more...
Name:
Email:
  Gravatar enabled.
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 
Security Image
Please input the anti-spam code that you can read in the image.
Unsubscribe from e-mail notifications.
 
< Prev   Next >
Subscribe

If 7374 people are reading this site every day, why don't you?