CSS3 Tutorial-Background

黄舟
Release: 2016-12-27 15:56:52
Original
1316 people have browsed it

Front-end development programmers, how happy it is to explain to you some knowledge about CSS3 tutorials every day. CSS3 contains multiple new background properties, which provide more powerful control over the background.

In this article, you will learn the following two background attributes:

1. background-size;

2. background-origin.

You will also learn how to use multiple background images.

Browser support

CSS3 Tutorial-Background

Let’s first understand the CSS3 background-size property:

CSS3 Tutorial-Background

background The -size attribute specifies the size of the background image.

Before CSS3, the size of the background image was determined by the actual size of the image. In CSS3, the size of the background image can be specified, which allows us to reuse the background image in different environments.

You can specify dimensions in pixels or percentages. If the dimensions are specified as a percentage, the dimensions are relative to the width and height of the parent element.

Example 1:

Adjust the size of the background image:

div
{
background:url(bg_flower.gif);
-moz-background-size:63px 100px; /* 老版本的 Firefox */
background-size:63px 100px;
background-repeat:no-repeat;
}
Copy after login

Example 2:

Stretch the background image so that it completely fills the content area :

div
{
background:url(bg_flower.gif);
-moz-background-size:40% 100%; /* 老版本的 Firefox */
background-size:40% 100%;
background-repeat:no-repeat;
}
Copy after login

Let’s take a look at the CSS3 background-origin attribute:

The background-origin attribute specifies the positioning area of ​​the background image.

The background image can be placed in the content-box, padding-box or border-box area.

CSS3 Tutorial-Background

Example:

Positioning the background image in the content-box:

div
{
background:url(bg_flower.gif);
background-repeat:no-repeat;
background-size:100% 100%;
-webkit-background-origin:content-box; /* Safari */
background-origin:content-box;
}
Copy after login

CSS3 multiple background images:

CSS3 Tutorial-Background

CSS3 allows you to use multiple background images for elements.

Example:

Set two background images for the body element:

body
{
background-image:url(bg_flower.gif),url(bg_flower_2.gif);
}
Copy after login

New background attribute:


CSS3 Tutorial-Background

The above is the content of CSS3 tutorial-background. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template