Home > Web Front-end > CSS Tutorial > How to set the background image size in css

How to set the background image size in css

青灯夜游
Release: 2023-01-05 16:08:26
Original
12079 people have browsed it

You can use the background-size attribute in css to set the size of the background image. The syntax is "background-size: value | percentage | cover | contain;"; where cover represents the proportional expansion of the image to fill the element, and contain represents Scale down the image proportionally to fit the element's dimensions.

How to set the background image size in css

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

css3 Set the size of the background image

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<style> 
body
{
	background:url(img_flwr.gif);
	background-size:80px 60px;
	background-repeat:no-repeat;
	padding-top:40px;
}
</style>
</head>
<body>
<p>
Lorem ipsum,中文又称“乱数假文”, 是指一篇常用于排版设计领域的拉丁文文章 ,主要的目的为测试文章或文字在不同字型、版型下看起来的效果。
</p>

<p>原始图片: <img src="/try/demo_source/img_flwr.gif"  alt="Flowers" width="224"    style="max-width:90%"></p>

</body>
</html>
Copy after login

How to set the background image size in css

##css3 background-size attribute## The #background-size attribute specifies the size of the background image; it can be used on Firefox, Chrome, and IE9.

The specific usage is as follows:

    Background image size (numeric representation):
  • #background-size{ 
    background-size:200px 100px; 
    }
    Copy after login
    Background image size (percentage representation):
  • #background-size2{ 
    background-size:30% 60%; 
    }
    Copy after login
    Background image size (expand the image proportionally to fill the element, that is, cover value):
  • #background-size3{ 
    background-size:cover; 
    }
    Copy after login
    Background image size (reducing the image proportionally to adapt to the size of the element, that is, the contain value):
  • #background-size4{ 
    background-size:contain; 
    }
    Copy after login
    Background image size (fill the element with the size of the image itself, that is, auto value):
  • ##

    #background-size5{ 
    background-size:auto; 
    }
    Copy after login
    (Learning video sharing: css video tutorial)

    The above is the detailed content of How to set the background image size in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
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