Home > Article > Web Front-end > How to set background for html
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')".
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:
#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:
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
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> body { background: pink url('smiley.gif') 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:
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!