The background-image
property is used to specify one or more images to use as the background of an element (see below for setting multiple-images).
By default, the background-image is placed at the top-left corner of an element, and repeated both vertically and horizontally, so that it covers the entire surface area of the element.
The background of an element is the total size of the element, including padding and border, but not including the margin.
The following is an example for specifying the background image values for various element types:
<!DOCTYPE html >
<html >
<head >
<style >
body {
background-image : url("grass.jpg") ;
background-color : green ;
}
h1 {
background-image : url("frame.png") ;
background-color : yellow ;
}
div {
background-image : url("sand.jpg ") ;
background-color : tan ;
}
p {
background-image : url("stone.jpg") ;
background-color : silver ;
}
label {
background-image : url("water.gif") ;
background-color : lightblue ;
}
</style >
</head >
<body >
<br />
<h1 >Hello World </h1 >
<br />
<div >This text is inside a div element.
<p >This paragraph, even though inside a div element, has its own background color. </p >
This is more text within the div element.
</div >
<br />
<label >This text is in a label element. </label >
<br />
</body >
</html >
This paragraph, even though inside a div element, has its own background color.
This is more text within the div element.Multiple images can be set by using the background-image property.
The following example shows how to set two background images for the body element, where sand.jpg is drawn first and then frame.png is drawn ontop of sand.jpg. This example works because frame.png uses an alpha color value that makes the inside of the frame transparent, allowing the sand.jpg to be visible through it:
<body {
background-image : url("frame.png"), url("sand.jpg") ;
}
This is an example having multiple images used as background-image.
Thank you for reading, I hope you found this blog post (tutorial) educational and helpful.
About | Contact Us | Privacy | Terms & Conditions | © 2024 - T&J Divisions, LLC, All Rights Reserved |