The way to set the position of the html background image is to add the background-position attribute to the background image and modify the appropriate attribute value, such as [background-position:center;].
The operating environment of this article: windows10 system, html 5, thinkpad t480 computer.
If we want to move the position of the background image in the html code, we can actually use the background-position attribute. Many students may not know this attribute yet. Let’s introduce this attribute below.
The background-position property is used to set the starting position of the background image.
Its common attribute values are as follows:
left top
left center
left bottom
right top
Code example:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> <style> body { background-image:url('smiley.gif'); background-repeat:no-repeat; background-attachment:fixed; background-position:center; } </style> </head> <body> <p><b>注意:</b>该属性工作在 Firefox 和 Opera, background-attachment 属性会被设置为 "fixed"。</p> </body> </html>
You can change the above Copy the code locally and run it to see the effect.
Related video sharing: html video tutorial
The above is the detailed content of How to set the position of the background image in html. For more information, please follow other related articles on the PHP Chinese website!