CSS3 background
CSS3 background
CSS3 contains several new background properties, providing greater control background elements.
In this chapter you will learn about the following background properties:
- background-image
- background-size
- background-origin
- background-clip
You will also learn how to use multiple background images.
Browser Support
Figures in the table represent the first browser to support the version number of the property.
Immediately following the digital -webkit-, -ms- or -moz- ago in support of the prefix attribute first browser version number.
Attributes | |||||
---|---|---|---|---|---|
background-image (With multiple backgrounds) | 4.0 | 9.0 | 3.6 | 3.1 | 11.5 |
background-size | 4.0 1.0 -webkit- | 9.0 | 4.0 3.6 -moz- | 4.1 3.0 -webkit- | 10.5 10.0 -o- |
background-origin | 1.0 | 9.0 | 4.0 | 3.0 | 10.5 |
background-clip | 4.0 | 9.0 | 4.0 | 3.0 | 10.5 |
CSS3 background-image property
CSS3 can add a background image via background-image property.
Different background image and the image separated by commas, all images are displayed at the top of the first.
Examples
background-image: url (img_flwr.gif), url (paper.gif);
background-position: right bottom, left top;
background-repeat: no-repeat, repeat;
}
You can set the number of different properties to different image
Examples
background: url (img_flwr.gif) right bottom no-repeat, url (paper.gif) left top repeat;
}
CSS3 background-size property
background-size specifies the size of the background image. CSS3 ago, the background image size is determined by the actual size of the image.
CSS3 can specify a background image, let us re-specify the size of the background image in different environments. You can specify a percentage or pixel size.
You specify the size is relative to the width and height of the parent element percentage size.
Example 1
Reset background image:
{
background: url (img_flwr.gif);
background-size: 80px 60px;
background-repeat: no-repeat;
}
Example 2
Stretch the background image to completely fill the content area:
{
background: url (img_flwr.gif);
background-size: 100% 100%;
background-repeat: no-repeat;
}
CSS3's background-Origin attribute
background-Origin attribute specifies the location of the background image area.
content-box, can be placed inside the padding-box, and border-box area of the background image.
Examples
Positioning a background image in the content-box:
{
background: url (img_flwr.gif);
background-repeat: no-repeat;
background-size: 100% 100%;
background-origin: content-box;
}
CSS3 multiple background images | |
CSS3 allows you to elements The add multiple background images. |
Examples
Set two background images in the body element:
{
background-image:url(img_flwr.gif),url(img_tree.gif);
}
CSS3 background-clip property
CSS3 The background-clip property background is cut to start drawing from the specified location
Examples
border: 10px dotted black;
padding: 35px;
background: yellow;
background-clip: content-box;
}
New background properties
order | description | CSS |
---|---|---|
background-clip | Provisions of the drawing area background. | 3 |
background-origin | Predetermined background image positioning region. | 3 |
background-size | Background image of a predetermined size. | 3 |