background-size

important note重要訊息:

本文件為初步資訊而且可能隨時變更。

設定背景影像的大小

語法

{ background-size: hSize[, vSize] }

可能的值

hSize, vSize

指定下列其中一個值的字串:

auto

預設值。影像的長寬比維持不變。如果 hSize 或 vSize 指派了長度或百分比值,影像將會縮放以符合這個值。如果 hSize 和 vSize 都設為 auto ,則影像會縮放成原始大小的 100%。

contain

影像的長寬比維持不變,並將影像縮放成背景定位區域內可容納的最大尺寸。

cover

影像的長寬比維持不變,並將影像縮放成可完全覆蓋背景定位區域的最小尺寸。

length

hSize 可指定影像的寬度,而 vSize 則可指定影像的高度。如果只指定 hSize 或 vSize,另一個值將會設為 auto

percentage

hSize 可指定影像的寬度,而 vSize 則可指定影像的高度。如果只指定 hSize 或 vSize,另一個值將會設為 auto 。百分比是以相對於背景定位區域來計算。

此屬性的預設值為 auto 。這不是繼承屬性。

標準資訊

您可以在 CSS Selectors Level 3 (CSS 選取器層級 3) Gg721772.xtlink_newWindow(zh-tw,Expression.40).png 找到此屬性的定義。

適用範圍

a, address, b, big, blockquote, body, button, caption, center, cite, code, col, colgroup, custom, dd, defaults, dfn, div, dl, dt, em, fieldset, form, hn, html, i, img, input type=button, input type=checkbox, input type=file, input type=image, input type=password, input type=radio, input type=reset, input type=submit, input type=text, li, ol, p, s, span, sub, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, var, xmp

另請參閱

概念

background
background-attachment
background-clip
background-color
background-image
background-origin
background-position
background-repeat