css

How to make a background image fit the whole window using CSS?

The following piece of code will solve the problem:

body{
background: url(‘../images/black_bg.png’) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
-ms-background-size: cover;
background-size: cover;
}

Cheers,

SZ

Advertisements

Centering an Image in CSS

I have been working with some designs and I had to center an image in few pages. Previously I used to use <center> tag around the image tag and it works like a charm. But the <center> tag is deprecated in HTML5 and there is a beautiful way around to do this using CSS. Add the following code to make the image aligned exactly to the center of any web page.

img{
margin-left: auto;
margin-right: auto;
text-align: center;
}

This piece of code works like a charm.

Cheers,

SZ