Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

background-image

Перевод не завершен. Пожалуйста, помогите перевести эту статью с английского.

Краткое описание

CSS свойство background-image устанавливает одно или несколько фоновых изображений для элемента. The images are drawn on stacking context layers on top of each other. The first layer specified is drawn as if it is closest to the user.

The borders of the element are then drawn on top of them, and the background-color is drawn beneath them. How the images are drawn relative to the box and its borders is defined by the background-clip and background-origin CSS properties.

If a specified image cannot be drawn (for example, when the file denoted by the specified URI cannot be loaded), browsers handle it as they would a none value.

Note: Even if the images are opaque and the color won't be displayed in normal circumstances, web developers should always specify a background-color. If the images cannot be loaded—for instance, when the network is down—the background color will be used as a fallback.

Начальное значениеnone
Применяется квсе элементы. Это также применяется к ::first-letter и ::first-line.
Наследуетсянет
Отображениевизуальный
Обработка значениякак указано, но с абсолютным URI
Анимируемостьнет
Канонический порядокуникальный не однозначный порядок, определённый формальной грамматикой

Синтаксис

background-image: none;
background-image: url(https://www.example.com/bck.png);

background-image: inherit;

Значения

none
Is a keyword denoting the absence of images.
<image>
Is an <image> denoting the image to display. There can be several of them, separated by commas, as multiple backgrounds are supported.

Formal syntax

<bg-image>#

where
<bg-image> = none | <image>

where
<image> = <url> | <image()> | <image-set()> | <element()> | <cross-fade()> | <gradient>

where
<image()> = image( [ [ <image> | <string> ]? , <color>? ]! )
<image-set()> = image-set( <image-set-option># )
<element()> = element( <id-selector> )
<cross-fade()> = cross-fade( <cf-mixing-image> , <cf-final-image>? )
<gradient> = <linear-gradient()> | <repeating-linear-gradient()> | <radial-gradient()> | <repeating-radial-gradient()>

where
<color> = <rgb()> | <rgba()> | <hsl()> | <hsla()> | <hex-color> | <named-color> | currentcolor | <deprecated-system-color>
<image-set-option> = [ <image> | <string> ] <resolution>
<cf-mixing-image> = <percentage>? && <image>
<cf-final-image> = <image> | <color>
<linear-gradient()> = linear-gradient( [ <angle> | to <side-or-corner> ]? , <color-stop-list> )
<repeating-linear-gradient()> = repeating-linear-gradient( [ <angle> | to <side-or-corner> ]? , <color-stop-list> )
<radial-gradient()> = radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> )
<repeating-radial-gradient()> = repeating-radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> )

where
<rgb()> = rgb( <rgb-component>#{3} )
<rgba()> = rgba( <rgb-component>#{3} , <alpha-value> )
<hsl()> = hsl( <hue>, <percentage>, <percentage> )
<hsla()> = hsla( <hue>, <percentage>, <percentage>, <alpha-value> )
<named-color> = <ident>
<deprecated-system-color> = ActiveBorder | ActiveCaption | AppWorkspace | Background | ButtonFace | ButtonHighlight | ButtonShadow | ButtonText | CaptionText | GrayText | Highlight | HighlightText | InactiveBorder | InactiveCaption | InactiveCaptionText | InfoBackground | InfoText | Menu | MenuText | Scrollbar | ThreeDDarkShadow | ThreeDFace | ThreeDHighlight | ThreeDLightShadow | ThreeDShadow | Window | WindowFrame | WindowText
<side-or-corner> = [ left | right ] || [ top | bottom ]
<color-stop-list> = <color-stop>{2,}
<ending-shape> = circle | ellipse
<size> = closest-side | farthest-side | closest-corner | farthest-corner | <length> | [ <length> | <percentage> ]{2}

where
<rgb-component> = <integer> | <percentage>
<alpha-value> = <number>
<hue> = <number>
<color-stop> = <color> [ <percentage> | <length> ]?

Примеры

Multiple backgrounds and transparency

Note that the star image is partially transparent and is layered over the cat image.

HTML Content

<div>
    <p class="catsandstars">
        This paragraph is full of cats<br />and stars.
    </p>
    <p>This paragraph is not.</p>
    <p class="catsandstars">
        Here are more cats for you.<br />Look at them!
    </p>
    <p>And no more.</p>
</div>

CSS Content

pre, p {
    font-size: 1.5em;
    color: #FE7F88;
    background-color: transparent;
}

div {
  background-image: url("https://mdn.mozillademos.org/files/6457/mdn_logo_only_color.png");
}

p {
  background-image: none;
}

.catsandstars {
  background-image:  url("https://mdn.mozillademos.org/files/11991/startransparent.gif"), 
                     url("https://mdn.mozillademos.org/files/7693/catfront.png");
  background-color: transparent;
}

Спецификации

Specification Status Comment
CSS Backgrounds and Borders Module Level 3
Определение 'background-image' в этой спецификации.
Кандидат в рекомендации From CSS2 Revision 1, the property has been extended to support multiple backgrounds and any <image> CSS data type.
CSS Level 2 (Revision 1)
Определение 'background-image' в этой спецификации.
Рекомендация From CSS1, the way images with and without intrinsic dimensions are handled is now described.
CSS Level 1
Определение 'background-image' в этой спецификации.
Рекомендация  

Совместимость браузеров

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 1.0 (1.7 или ранее)[1] 4.0 3.5 1.0
Multiple backgrounds 1.0 3.6 (1.9.2) 9.0 yes 1.3
Gradients 1.0-webkit 3.6 (1.9.2)-moz 10 11+-o 4.0-webkit
SVG images 8.0 4.0 (2.0) 9.0 9.5 5.0 [2]
element ? (Да)-moz Нет Нет Нет
image-rect Нет (Да)-moz Нет Нет Нет
Any <image> value. ? Нет ? ? ?
Feature iOS Safari Opera Mini Opera Mobile Android Browser
Basic support yes yes yes yes
Multiple backgrounds yes yes yes yes
Gradients yes -webkit
old webkit syntax for iOS 4.2 and older
? ? yes-webkit
old webkit syntax
SVG images yes [2] yes yes Нет
element (Да)-moz ? ? ?
image-rect (Да)-moz Нет Нет Нет
Any <image> value Нет ? ? ?

[1] If the browser.display.use_document_colors user preference in about:config is set to false, background images will not de displayed.

[2] Support of SVG in CSS background is incomplete in the current version of iOS Safari (5.0). The same for Safari prior 5.0.

Смотрите также

Метки документа и участники

 Внесли вклад в эту страницу: wizAmit, SphinxKnight, teoli, s1lver, Sebastianz, Aleksej, russian
 Обновлялась последний раз: wizAmit,