I'd thought about this sort of thing for CSS a number of years ago when I started off with HTML/CSS. At the time I knew nothing of Javascript or how to conjure up such a useful tool. Others however seem to have the know how and as such have built two handy frameworks that allow you to include functions, variables etc. in your CSS. Have a look at http://lesscss.org/ and http://sass-lang.com/