Home  >  Article  >  Web Front-end  >  How to set background image in css

How to set background image in css

王林
王林Original
2021-05-14 14:22:1210198browse

The way to set the background image in css is to use the background-image attribute, such as [background-image:url();]. An element's background takes up the full size of the element, including padding and borders, but not margins.

How to set background image in css

The operating environment of this article: windows10 system, css 3, thinkpad t480 computer.

In CSS we can use the background-image attribute to set a background image for an element. An element's background occupies the entire size of the element, including padding and borders, but not margins.

By default, the background image is placed in the upper left corner of the element and repeats horizontally and vertically.

For example:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php.cn</title> 
<style>
body 
{
	background-image:url(&#39;https://xxx.com/images/mix/paper.gif&#39;);
	background-color:#cccccc;
}
</style>
</head>

<body>
<h1>Hello World!</h1>
</body>

</html>

Related learning video sharing: css video tutorial

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

Statement:
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