--- title: background-position slug: Web/CSS/background-position translation_of: Web/CSS/background-position ---
A propriedade CSS background-position define a posição inicial, relativa a posição de fundo na camada definido por {{cssxref("background-origin")}}, para cada background image definido.
A fonte deste exemplo interativo está alocado em um repositório GitHub. Se você pudesse contribuir com os exemplos de projetos interativos , por favor "clone" https://github.com/mdn/interactive-examples e envie-nos um pull request.
/* Valores chave */ background-position: top; background-position: bottom; background-position: left; background-position: right; background-position: center; /* Valores <percentuais> */ background-position: 25% 75%; /* valores <espessura> */ background-position: 0 0; background-position: 1cm 2cm; background-position: 10ch 8em; /* Multiplas imagens */ background-position: 0 0, center; /* Valores de cantos relativos */ background-position: bottom 10px right 20px; background-position: right 3em bottom 10px; background-position: bottom 10px right; background-position: top right 10px; /* Valores globais */ background-position: inherit; background-position: initial; background-position: unset;
A propriedade background-position é especificada como um determinado numero de valores de <position> , separados por espaços.
<position>center.1-value syntax: the value may be:
center, which centers the image.top, left, bottom, right. This specifies an edge against which to place the item. The other dimension is then set to 50%, so the item is placed in the middle of the edge specified.2-value syntax: one value defines X and the other defines Y. Each value may be:
top, left, bottom, right. If left or right are given here, then this defines X and the other given value defines Y. If top or bottom are given, then this defines Y and the other value defines X.left or right, then this value defines Y, relative to the top edge. If the other value is top or bottom, then this value defines X, relative to the left edge. If both values are <length> or <percentage> values, then the first defines X and the second Y.Note that:
top or bottom, then the other value may not be top or bottom.left or right, then the other value may not be left or right.This means, e.g., that top top and left right are not valid.
Each of these three examples uses the {{cssxref("background")}} property to create a yellow, rectangular element containing a star image. In each example, the star is in a different position. The third example illustrates how to specify positions for two different background images within one element.
<div class="exampleone">Example One</div> <div class="exampletwo">Example Two</div> <div class="examplethree">Example Three</div>
/* Shared among all <div>s */
div {
background-color: #FFEE99;
background-repeat: no-repeat;
width: 300px;
height: 80px;
margin-bottom: 12px;
}
/* These examples use the `background` shorthand property */
.exampleone {
background: url("https://mdn.mozillademos.org/files/11987/startransparent.gif") #FFEE99 2.5cm bottom no-repeat;
}
.exampletwo {
background: url("https://mdn.mozillademos.org/files/11987/startransparent.gif") #FFEE99 3em 50% no-repeat;
}
/* Multiple background images: Each image is matched with the
corresponding position, from first specified to last. */
.examplethree {
background-image: url("https://mdn.mozillademos.org/files/11987/startransparent.gif"),
url("https://mdn.mozillademos.org/files/7693/catfront.png");
background-position: 0px 0px,
center;
}
{{EmbedLiveSample('Examples', 420, 200)}}
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('CSS3 Backgrounds', '#background-position', 'background-position')}} | {{Spec2('CSS3 Backgrounds')}} | Adds support for multiple backgrounds and the four-value syntax. Modifies the percentage definition to match implementations. |
| {{SpecName('CSS2.1', 'colors.html#propdef-background-position', 'background-position')}} | {{Spec2('CSS2.1')}} | Allows for keyword values and {{cssxref("<length>")}} and {{cssxref("<percentage>")}} values to be mixed. |
| {{SpecName('CSS1', '#background-position', 'background-position')}} | {{Spec2('CSS1')}} | Initial definition. |
{{cssinfo}}
{{Compat("css.properties.background-position")}}
background-position can't be {{cssxref("transition","transitioned")}} between two values containing different numbers of {{cssxref("<position>")}} values, for example background-position: 10px 10px; and background-position: 20px 20px, 30px 30px; (see {{bug(1390446)}}). Firefox's new parallel CSS engine (also known as Quantum CSS or Stylo, planned for release in Firefox 57) fixes this.