Home >Web Front-end >CSS Tutorial >How to set the background image to be adaptively centered in css

How to set the background image to be adaptively centered in css

王林
王林Original
2021-03-09 16:30:055086browse

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.

How to set the background image to be adaptively centered in css

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(&#39;smiley.gif&#39;);
	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!

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