Home > Web Front-end > CSS Tutorial > A detailed introduction to the background-size property in CSS3

A detailed introduction to the background-size property in CSS3

php中世界最好的语言
Release: 2017-11-30 16:34:49
Original
2748 people have browsed it

We know that there is a very important attribute in CSS3, the bachground-size attribute. Its function is to define the size of the background image. There are 5 values, auto, pixel value, percentage, cover, and contain. Today I will teach you how to use the bachground-size attribute.

background-size:auto, the default value, fills the element with the size of the image itself, adjusts its own proportion according to the size of the element, and does not deform the image.

CSS3 about the background-size attribute

1.

<!DOCTYPE html><html><head>
<meta charset="utf-8">
<title>background-size属性</title>
<style type="text/css">
div{
width:300px;
height:150px;
border:1px solid black;
background:url("photo.jpg") no-repeat;
}
</style></head><body>
<div></div></body></html>
Copy after login

2. The size of the background image itself—width: 200px, height: 133px. The rendering of the above code is as follows:

Pixel values, such as 30px 50px, respectively represent width height

CSS3 about the background-size attribute

<!DOCTYPE html><html><head>
<meta charset="utf-8">
<title>background-size属性</title>
<style type="text/css">
div{
width:300px;
height:150px;
border:1px solid black;
background:url("photo.jpg") no-repeat;
background-size:250px 100px;
}
</style></head><body>
<div></div></body></html>
Copy after login


I believe you have read these cases You have mastered the method. For more exciting information, please pay attention to other related articles on the php Chinese website!

Related reading:

Tutorial on using the transform attribute in Css3

Detailed introduction to the border-image attribute in Css3

Several ways to position in front-end projects

The above is the detailed content of A detailed introduction to the background-size property in CSS3. For more information, please follow other related articles on the PHP Chinese website!

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