Home > Web Front-end > Front-end Q&A > How to use css background-position property

How to use css background-position property

青灯夜游
Release: 2019-05-30 09:21:21
Original
4204 people have browsed it

The background-position property is used to set the starting position of the background image. The syntax is background-position: x y, where x represents the horizontal position and y represents the vertical position; there are many ways to assign values ​​to x and y, for example: top left, 3% 2%, xpos ypos.

How to use css background-position property

How to use the css background-position property?

The background-position property can set the starting position of the background image.

Syntax:

background-position: x y
Copy after login

Values ​​that can be set:

Value
Description
left top
left center
left bottom
right top
right center
right bottom
center top
center center
center bottom
If only one keyword is specified, the other values ​​will be "center"
x% y%The first value is the horizontal position, the second value is the vertical position. The upper left corner is 0% 0%. The lower right corner is 100% 100%. If only one value is specified, the other values ​​will be 50%. . The default value is: 0% 0%
xpos yposThe first value is the horizontal position and the second value is the vertical. The upper left corner is 0. Units can be pixels (0px0px) or any other CSS unit. If only one value is specified, the other values ​​will be 50%. You can mix % and positions

Description: This attribute sets the position of the background original image (defined by background-image), the background image if you want Repeat, starting from this point.

Note: You need to set the background-attachment property to "fixed" to ensure that this property works properly in Firefox and Opera.

css background-position property example

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<style type="text/css">
body
{ 
  background-image:url(&#39;https://img.php.cn/upload/article/000/005/656/5af270fd37755429.jpg&#39;);
  background-repeat:no-repeat;
  background-attachment:fixed;
  background-position:center;
}
</style>
</head>
<body>
<body>
<p><b>提示:</b>您需要把 background-attachment 属性设置为 "fixed",才能保证该属性在 Firefox 和 Opera 中正常工作。</p>
</body>
</body>
</html>
Copy after login

The above is the detailed content of How to use css background-position property. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
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