background

英 [ˈbækgraʊnd]   美 [ˈbækˌɡraʊnd]  

n.(画等的)背景;底色;背景资料;配乐

复数: backgrounds

position

英 [pəˈzɪʃn]   美 [pəˈzɪʃən]  

n.位置,方位;地位,职位;态度;状态

vt.安置;把…放在适当位置;给…定位;驻扎军队

第三人称单数: positions 复数: positions 现在分词: positioning 过去式: positioned 过去分词: positioned

css background-position属性 语法

background-position属性怎么用?

background-position属性可以设置背景图像的起始位置。语法为:background-position: x y,其中x表示水平位置,y表示垂直位置;x和y有多种赋值方式,例:top left,3% 2%,xpos ypos。

作用:设置背景图像的起始位置。

说明:这个属性设置背景原图像(由 background-image 定义)的位置,背景图像如果要重复,将从这一点开始。

注释:您需要把 background-attachment 属性设置为 "fixed",才能保证该属性在 Firefox 和 Opera 中正常工作。

可以设置的值:

描述

top left

top center

top right

center left

center center

center right

bottom left

bottom center

bottom right

如果您仅规定了一个关键词,那么第二个值将是"center"。

默认值:0% 0%。

x% y%

第一个值是水平位置,第二个值是垂直位置。 

左上角是 0% 0%。右下角是 100% 100%。

如果您仅规定了一个值,另一个值将是 50%。


xpos ypos

第一个值是水平位置,第二个值是垂直位置。

左上角是 0 0。单位是像素 (0px 0px) 或任何其他的 CSS 单位。

如果您仅规定了一个值,另一个值将是50%。

您可以混合使用 % 和 position 值。

css background-position属性 示例

<html>
<head>
<style type="text/css">
body
{ 
  background-image:url('http://img.php.cn/upload/article/000/005/656/5af270fd37755429.jpg');
  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>

运行实例 »

点击 "运行实例" 按钮查看在线实例

热门推荐