Home >Web Front-end >CSS Tutorial >How to set the background image to be adaptively centered in css
How to set the background image adaptive centering in css: You can set it with the help of the background-position attribute, such as [background-positiion:center;], the attribute value center means centering.
The operating environment of this article: windows10 system, css 3, thinkpad t480 computer.
Attribute introduction:
In CSS, if we want a picture to be displayed vertically in the center, then we can use the background-position attribute to achieve this.
Property introduction:
The background-position property sets the starting position of the background image.
For example, if we want to use a local image as the background and center it, then we can do this:
<!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>
Related recommendations: CSS tutorial
The above is the detailed content of How to set the background image to be adaptively centered in css. For more information, please follow other related articles on the PHP Chinese website!