Skip to content

Instantly share code, notes, and snippets.

@JossWhittle
Created August 6, 2012 14:37
Show Gist options
  • Save JossWhittle/3274910 to your computer and use it in GitHub Desktop.
Save JossWhittle/3274910 to your computer and use it in GitHub Desktop.
Colour Bar using HTML + CSS + JQuery
.colbar {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 7px; /* <-- Edit this to change the height */
display: table;
table-layout: fixed;
}
.col {
position: relative;
display: table-cell;
height:100%;
}
.red {
background: #641717;
}
.blue {
background: #173F64;
}
.green {
background: #2B6417;
}
.yellow {
background: #644F17;
}
.teal {
background: #175C64;
}
<!-- You can either just run the jquery on a given div -->
<div id="bar"></div>
<!-- Or you can hard code it... -->
<div class="colbar">
<div class="col red"></div>
<div class="col blue"></div>
<div class="col green"></div>
<div class="col yellow"></div>
<div class="col teal"></div>
</div>
$(function(){
$('#bar').colourification(8);
// It looks really cool at 20 and 50 too! :D
});
$.fn.colourification = function(n) {
var colours = ["red","blue","green","yellow","teal"];
this.each(function() {
$(this).addClass('colbar').empty();
for (var i = 0; i < n; i++) {
$(this).append('<div class="col ' + colours[i % colours.length] + '"></div>');
}
});
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment