css div as background image code example

Example 1: div background image

#avatar {
    /* This image is 687 wide by 1024 tall, similar to your aspect ratio */
    background-image: url('http://i.stack.imgur.com/Dj7eP.jpg');
    
    /* make a square container */
    width: 150px;
    height: 150px;

    /* fill the container, preserving aspect ratio, and cropping to fit */
    background-size: cover;

    /* center the image vertically and horizontally */
    background-position: top center;

    /* round the edges to a circle with border radius 1/2 container size */
    border-radius: 50%;
}

Example 2: add background image in css

.w {
background-image: url("images/tom1.png");
}

.a {
background-image: url("images/tom2.png");
}

.s {
background-image: url("images/tom3.png");
}

Example 3: how to set div background image

body {
 background-image: url("paper.gif");
 background-color: #cccccc;
}

Tags:

Css Example