CSS agtergrondposisie Eiendom
Voorbeeld
Hoe om 'n agtergrondprent te plaas:
body
{
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}
Meer "Probeer dit self" voorbeelde hieronder.
Definisie en gebruik
Die background-position
eiendom stel die beginposisie van 'n agtergrondprent.
Wenk: By verstek word 'n agtergrondprent in die boonste linkerhoek van 'n element geplaas en beide vertikaal en horisontaal herhaal.
Standaard waarde: | 0% 0% |
---|---|
Geërf: | geen |
Animateerbaar: | ja. Lees oor animeerbaar |
Weergawe: | CSS1 |
JavaScript-sintaksis: | voorwerp .style.backgroundPosition="center" |
Blaaierondersteuning
Die nommers in die tabel spesifiseer die eerste blaaierweergawe wat die eiendom ten volle ondersteun.
Property | |||||
---|---|---|---|---|---|
background-position | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Let wel: IE8 en vroeër ondersteun nie veelvuldige agtergrondprente op een element nie.
CSS-sintaksis
background-position: value;
Eiendomswaardes
Value | Description | Play it |
---|---|---|
left top left center left bottom right top right center right bottom center top center center center bottom |
If you only specify one keyword, the other value will be "center" | |
x% y% | The first value is the horizontal position and the second value is the vertical. The top left corner is 0% 0%. The right bottom corner is 100% 100%. If you only specify one value, the other value will be 50%. Default value is: 0% 0% | |
xpos ypos | The first value is the horizontal position and the second value is the vertical. The top left corner is 0 0. Units can be pixels (0px 0px) or any other CSS units. If you only specify one value, the other value will be 50%. You can mix % and positions | |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
Meer voorbeelde
Voorbeeld
Hoe om 'n agtergrondprent te posisioneer om bo gesentreer te wees:
body
{
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center top;
}
Voorbeeld
Hoe om 'n agtergrondprent regs onder te plaas:
body
{
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: bottom right;
}
Voorbeeld
Hoe om 'n agtergrondprent te plaas met persentasie:
body
{
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: 50% 50%;
}
Voorbeeld
Hoe om 'n agtergrondprent met behulp van pixels te plaas:
body
{
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: 50px 150px;
}
Voorbeeld
Gebruik verskillende agtergrondeienskappe om 'n "held"-beeld te skep:
.hero-image {
background-image: url("photographer.jpg"); /* The
image used */
background-color: #cccccc; /* Used if the image is
unavailable */
height: 500px; /* You must set a specified height */
background-position: center; /* Center the image */
background-repeat: no-repeat; /* Do not repeat the image */
background-size: cover; /* Resize the background image to cover the entire container */
}
Verwante bladsye
CSS-tutoriaal: CSS-agtergrond
CSS verwysing: agtergrond-beeld eiendom
HTML DOM-verwysing: agtergrondposisie-eienskap