CSS給背景圖定位

來源:互聯網
上載者:User

background-position:
| [percentage | length]{1,2}
|[top | center | bottom]
| [left | center | right] www.86oo.com

background-position:[percentage | length]是用X(橫座標)y(縱座標)定義,如background-position: 20px 40px; http://www.86oo.com

background-position:[top | center | bottom] 和[left | center | right] 是一樣的意思了,三個任意兩個搭配可以產生不同的效果.
可以是background-position:top center;center bottom;top bottom;left,right.....

www.86oo.com

bottom:下,top:上,left:左,right:右,center:中.

www.86oo.com

下為像素與英文的對照:
top left = left top = 0% 0%
top = top center = center top = 50% 0%
right top = top right = 100% 0%
left = left center = center left = 0% 50%
center = center center = 50% 50%
right = right center = center right = 100% 50%
bottom left = left bottom = 0% 100%
bottom = bottom center = center bottom = 50% 100%
bottom right = right center = 100% 100%

86oo精彩教程

background可以用來給指定的層填充背景色、背景圖片,格式如下:

86oo.com歡迎你

background:#ccc url('bg.gif') top left no-repeat;
表示:使用#CCC(灰階色)填充整個層,使用bg.gif做為背景圖片,
top left表示圖片位於當前層的左上端,no-repeat表示僅顯示圖片大小而不填充滿整個層。
top/right/left/bottom/center用於定位背景圖片,分別表示 上 / 右 / 下 / 左 / 中;

86oo.com提供各類教程

background:url('bg.gif') 20px 100px;
表示X座標為20像素,Y座標為100像素的精確定位;

86oo.com

repeat/no-repeat/repeat-x/repeat-y
分別表示 填充滿整個層 / 不填充 / 沿X軸填充 / 沿Y軸填充。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.