Home  >  Article  >  Web Front-end  >  How to set background for html

How to set background for html

青灯夜游
青灯夜游Original
2021-07-01 14:17:5762571browse

htmlHow to set the background: 1. Use the bgcolor attribute of the body tag to set the background color; 2. Use the background attribute of the body tag to set the background image; 3. Use the style attribute in the body tag and add "background: Color value/url('picture path')".

How to set background for html

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

htmlSet the background

1. The bgcolor attribute of the body tag

bgcolor attribute specification document background color.

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
</head>
<body bgcolor="#E6E6FA">
<h1>Hello world!</h1>
</body>
</html>

Rendering:

How to set background for html

#Note: If you use color names, the rendering structures of different browsers are different. If you use RGB codes, Firefox The browser cannot display the correct color.

Tip: If all browsers want to display the same color, use hexadecimal color codes.

2. The background attribute of the body tag

The background attribute specifies the background image of the document.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body background="demo/img/1.jpg">
</body>
</html>

Rendering:

How to set background for html

3. css background attribute

The background attribute is an abbreviation Properties, you can set all background properties in one statement.

The properties that can be set are:

  • background-color

  • background-position

  • background-size

  • background-repeat

  • ##background-origin

  • background-clip

  • background-attachment

  • background-image

Example:


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<style>
body
{ 
background: pink url(&#39;smiley.gif&#39;) no-repeat fixed center; 
}
</style>
</head>

<body>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
</body>

</html>

Rendering:


How to set background for html

Recommended tutorial: "

html video tutorial"

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