You'll need javascript, I suggest you use jQuery as it simplifies things quite a bit: http://jquery.com/
And then write a script, something like:
$(window).on('scroll', function(e) {
var scrollTop = $('body').scrollTop();
if (scrollTop > 300) { //300 is pixels you scrolled, it's just an example
$('.header').addClass("fixed");
} else {
$('.header').removeClass("fixed");
}
})
And in your css you will need to set up the .fixed class:
.header {
position: static;
}
.header.fixed {
position: fixed;
top:0
}
EDIT:
Here's a fiddle to demonstrate how to use it: http://jsfiddle.net/nY2ek/