欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

CSS background-position的使用說(shuō)明詳解

  發(fā)布時(shí)間:2009-12-17 14:05:06   作者:佚名   我要評(píng)論
設(shè)置或檢索對(duì)象的背景圖像位置。必須先指定 background-image 屬性。該屬性定位不受對(duì)象的補(bǔ)丁屬性( padding )設(shè)置影響
background-position的說(shuō)明:
設(shè)置或檢索對(duì)象的背景圖像位置。必須先指定 background-image 屬性。該屬性定位不受對(duì)象的補(bǔ)丁屬性( padding )設(shè)置影響。
默認(rèn)值為: 0% 0% 。此時(shí)背景圖片將被定位于對(duì)象不包括補(bǔ)丁( padding )的內(nèi)容區(qū)域的左上角。
如果只指定了一個(gè)值,該值將用于橫坐標(biāo)??v坐標(biāo)將默認(rèn)為 50% 。如果指定了兩個(gè)值,第二個(gè)值將用于縱坐標(biāo)。
如果設(shè)置值為 right center,因?yàn)?right 作為橫坐標(biāo)值將會(huì)覆蓋 center 值,所以背景圖片將被居右定位。
對(duì)應(yīng)的腳本特性為 backgroundPosition 。

語(yǔ)法:
background-position : length || length
background-position : position || position

取值:
length : 百分?jǐn)?shù) | 由浮點(diǎn)數(shù)字和單位標(biāo)識(shí)符組成的長(zhǎng)度值。
position : top | center | bottom | left | center | right

background-position -- 定義背景圖片的位置

取值:
[ <percentage> | <length> | left | center | right ] [ <percentage> | <length> | top | center | bottom ] ]
* 水平
left: 左
center: 中
right: 右
* 垂直
top: 上
center: 中
bottom: 下
* 垂直與水平的組合
x-% y-%
x-pos y-pos

初始值: 0% 0%
繼承性: 否
適用于: 所有元素
background:背景.position:位置.

重點(diǎn)講解的地方:

復(fù)制代碼
代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="UTF-8">
<head>
<title>背景圖片的定位background-position的問(wèn)題</title>
<style type="text/css">
<!--
*{
margin:0;
padding:0;
}
body {
text-align:center;
background:#000;
}
#container{
width:1000px;
margin:0 auto;
background:#fff url(images/bg.jpg) no-repeat left top;
height:500px;
}
-->
</style>
</head>
<body>
<div id="container"> </div>
</body>
</html>

圖片:
 
一.background-position:left top;(見(jiàn)圖1).
背景圖片的左上角和容器(container)的左上角對(duì)齊,超出的部分隱藏。
等同于 background-position:0,0;
也等同于background-position:0%,0%;

二.background-position:right bottom;(見(jiàn)圖2)。
背景圖片的右下角和容器(container)的右下角對(duì)齊,超出的部分隱藏。
等同于background-positon:100%,100%;
也等同于background-positon:容器(container)的寬度-背景圖片的寬度,容器(container)的高度-背景圖片的高度

三.background-position:500px 15px;(見(jiàn)圖3)。
背景圖片從容器(container)左上角的地方向右移500px,向下移15px,超出的部分隱藏。

四.background-position:-500px -15px;(見(jiàn)圖4)。
背景圖片從容器(container)左上角的地方向左移500px,向上移15px,超出的部分隱藏。

五.background-position:50% 50%;(見(jiàn)圖5)。
等同于left:{容器(container)的寬度—背景圖片的寬度}*left百分比,超出的部分隱藏。
等同于right:{容器(container)的高度—背景圖片的高度}*right百分比,超出的部分隱藏。
例如:background-position:50% 50%;就是background-position:(1000-2000)*50%px,(500-30)*50%px;即background-position:-500px,235px;也就是背景圖片從容器(container)的左上角向左移500px,向下移235px;

六.background-position:-50% -50%;(見(jiàn)圖6)。
(這種情況背景圖片應(yīng)該用bg2.jpg才能看出效果,bg.jpg的高度太小效果不明顯)
等同于left:-{{容器(container)的寬度—背景圖片的寬度}*left百分比(百分比都取正值)},超出的部分隱藏。
等同于right:-{{容器(container)的高度—背景圖片的高度}*right百分比(百分比都取正值)},超出的部分隱藏。
例如:background-position:-50% -50%;就是background-position:-{(1000-500)*50%}px,-{(500-360)*50%}px;即background- position:-250px,-70px;也就是背景圖片從容器(container)的左上角向左移250px,向上移70px;下面是網(wǎng)上的其它文章。
background-position -- 定義背景圖片的位置
取值: [ [ <percentage> | <length> | left | center | right ] [ <percentage> | <length> | top | center | bottom ]? ] | [ [ left | center | right ] || [ top | center | bottom ] ] | inherit
水平
left: 左
center: 中
right: 右
垂直
top: 上
center: 中
bottom: 下
垂直與水平的組合
x-% y-%
x-pos y-pos
inherit: 繼承
初始值: 0% 0%
繼承性: 否
適用于: 所有元素
background:背景.position:位置.
注:background-position屬性是CSS2.1提出的.IE6,Firefox1.5,Opera9支持此屬性

示例
body {
background-image:url('list-orange.png');
background-repeat:no-repeat;
}
p {
background-image:url('list-orange.png');
background-position:right bottom ;
background-repeat:no-repeat;
}
div {
background-image:url('list-orange.png');
background-position:50% 20% ;
background-repeat:no-repeat;
}
屏幕左上角顯示一個(gè)橙色點(diǎn).p段落的左下角顯示一個(gè)橙色點(diǎn).div中間偏上顯示一個(gè)橙色點(diǎn).

說(shuō)明
background-position屬性是通過(guò)平面上的x與y坐標(biāo)定位的,所以通常取兩個(gè)值.
例如:
<percentage> <percentage>
左上角為0%, 0%. 右下角為100%, 100%.例如58%,56%就是從左上角算起,右移58%,下移56%.
<length> <length>
6cm 8cm,從左上角算起,右移6cm,下移8cm.
更多內(nèi)容,請(qǐng)看腳本之家最近更新的文章。重點(diǎn)介紹css background-position

相關(guān)文章

最新評(píng)論