Home > Web Front-end > HTML Tutorial > How to set background image in html

How to set background image in html

青灯夜游
Release: 2021-04-30 18:17:48
Original
81472 people have browsed it

Setting method: 1. Use the background attribute, the syntax "

"; 2. Use the background-image attribute, the syntax "".

How to set background image in html

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

Method 1: Use the body background attribute

The body background attribute specifies the background image of the document. The syntax is as follows:

<body background="URL">
Copy after login

Example:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body background="img/1.jpg">
添加背景图片
</body>
</html>
Copy after login

Rendering:

How to set background image in html

Method 2: Use css background-image property

background-image property sets the background image of an element.

The background of an element is the total 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 vertically and horizontally.

Example:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
	</head>
	<body style="background-image: url(img/3.jpg);">
		添加背景图片
	</body>
</html>
Copy after login

Rendering:

How to set background image in html

##Recommended tutorial: "

html video tutorial"

The above is the detailed content of How to set background image in html. 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