Category Archives: CSS

Sticky header jQuery

In order to have a sticky header you need these elements:

[html]

nav here

[/html]

and …

[css]

#header_nav {
width:100%;
height:100px;
background-color:#666;
position:fixed;
top:0;
left:0;
}

[/css]

… and …

[js]

$(function(){
$(‘#header_nav’).data(‘size’,’big’);
});

$(window).scroll(function(){
if($(document).scrollTop() > 0)
{
if($(‘#header_nav’).data(‘size’) == ‘big’)
{
$(‘#header_nav’).data(‘size’,’small’);
$(‘#header_nav’).stop().animate({
height:’40px’
},600);
}
}
else
{
if($(‘#header_nav’).data(‘size’) == ‘small’)
{
$(‘#header_nav’).data(‘size’,’big’);
$(‘#header_nav’).stop().animate({
height:’100px’
},600);
}
}
});

[/js]

 

Guess what!? It works!

Stretch and scale body background image

Use this style definition to have a background image stretched to view port without multiplying it.

[css]

body{
background: url(wallpaper-abstract.jpg) no-repeat center center fixed;
-webkit-background-size: cover; /*for webKit*/
-moz-background-size: cover; /*Mozilla*/
-o-background-size: cover; /*opera*/
background-size: cover; /*generic*/
}

[/css]

Force favicon refresh

To refresh your site’s favicon you can force browsers to download a new version using the link tag and a querystring on your filename. This is especially helpful in production environments to make sure your users get the update.

<link rel="shortcut icon" href="http://www.yoursite.com/favicon.ico?v=2" />