How to set the position of the background image in html

王林
Release: 2023-01-06 11:17:38
Original
13500 people have browsed it

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;].

How to set the position of the background image in html

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(&#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

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!

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!