background image of div code example
Example 1: css background image
background-image: url("image.png");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
Example 2: 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 3: html background image
<head>
<style>
body {
background-image: url(https://wallup.net/wp-content/uploads/2019/09/110394-cats-grey-kittens-fluffy-fat-grass-animals-cat-kitten-baby-cute-748x468.jpg)
}
</style>
<body>
You have set the background image!
</body>
Example 4: background image
div {
background-color: #ffffff;
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-attachment: scroll|fixed|local|initial|inherit;
background-position: right top | x% y% | xpos ypos;
background-clip: border-box|padding-box|content-box|initial|inherit;
background-size: auto|length|cover|contain|initial|inherit;
}
//shorthand:
div {
background: #ffffff url("img_tree.png") no-repeat right top;
}
Example 5: make image background of div
background-image: url("photographer.jpg");
Example 6: how to set div background image
body {
background-image: url("paper.gif");
background-color: #cccccc;
}