CSSの背景の速記
CSSの背景-省略形のプロパティ
コードを短くするために、1つのプロパティですべての背景プロパティを指定することもできます。これは省略形プロパティと呼ばれます。
書く代わりに:
body {
background-color: #ffffff;
background-image:
url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
}
省略形のプロパティを使用できますbackground
:
例
省略形のプロパティを使用して、1つの宣言で背景プロパティを設定します。
body {
background: #ffffff url("img_tree.png") no-repeat right top;
}
省略形のプロパティを使用する場合、プロパティ値の順序は次のとおりです。
background-color
background-image
background-repeat
background-attachment
background-position
他の値がこの順序である限り、プロパティ値の1つが欠落しているかどうかは関係ありません。上記の例では、値がないため、background-attachmentプロパティを使用していないことに注意してください。
すべてのCSS背景プロパティ
Property | Description |
---|---|
background | Sets all the background properties in one declaration |
background-attachment | Sets whether a background image is fixed or scrolls with the rest of the page |
background-clip | Specifies the painting area of the background |
background-color | Sets the background color of an element |
background-image | Sets the background image for an element |
background-origin | Specifies where the background image(s) is/are positioned |
background-position | Sets the starting position of a background image |
background-repeat | Sets how a background image will be repeated |
background-size | Specifies the size of the background image(s) |