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

王林
Release: 2023-01-03 09:28:44
Original
5049 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!