Skip to content

Instantly share code, notes, and snippets.

@mhkeller
Created September 27, 2012 19:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhkeller/3796135 to your computer and use it in GitHub Desktop.
Save mhkeller/3796135 to your computer and use it in GitHub Desktop.
Stacked bar chart in HTML/CSS
All of the google results for this are outdated / don't work. Here's a simple fiddle that stakes div relative to the bottom of its container div.
http://jsfiddle.net/9pXpU/
<div class="colWrapper">
<div class="barContainer">
<div class="bar" style="background-color:#b4cde2;"></div>
<div class="bar" style="background-color:#7ca7cc;"></div>
<div class="bar" style="background-color:#6094c1;"></div>
<div class="bar" style="background-color:#3b6d97;"></div>
</div>
</div>​
.colWrapper{
height:200px;
width:100px;
position:relative;
border:1px solid #ccc;
}
.barContainer{
position:absolute;
bottom:0;
width:100%;
}
.bar{
widith:100%;
height:20px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment