• 密码登录
  • 手机登录
社交账号登录
阅读( ) 收藏( ) 加载中~ 我要纠错

代码实例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<style>
body
{ 
	background:url("/uploads/allimg/20221223/1-221223161543561.png");
	background-repeat:no-repeat;
	background-attachment:fixed;
	background-position:center; 
}
</style>
</head>

<body>
<p><b>注意:</b> 该属性工作在 Firefox 和 Opera, background-attachment 属性会被设置为 "fixed".</p>
</body>
</html>

尝试一下 »

点击“尝试一下”按钮查看在线实例

定义和用法

background-position属性设置背景图像的起始位置。

注意对于这个工作在Firefox和Opera,background-attachment必须设置为 "fixed(固定)"。

语法


background-position: horizontal vertical

水平是

percentage | length | left | center | right

垂直是

percentage | length | top | center | bottom



属性值

描述
left top
left center
left bottom
right top
right center
right bottom
center top
center center
center bottom
如果仅指定一个关键字,其他值将会是"center"
x% y%第一个值是水平位置,第二个值是垂直。左上角是0%0%。右下角是100%100%。如果仅指定了一个值,其他值将是50%。 。默认值为:0%0%
xpos ypos第一个值是水平位置,第二个值是垂直。左上角是0。单位可以是像素(0px0px)或任何其他 CSS单位。如果仅指定了一个值,其他值将是50%。你可以混合使用%和positions
inherit指定background-position属性设置应该从父元素继承


×