CSS- positie Eigenschap
Voorbeeld
Plaats een <h2> element:
h2
{
position: absolute;
left: 100px;
top: 150px;
}
Meer "Probeer het zelf" voorbeelden hieronder.
Definitie en gebruik
De position
eigenschap specificeert het type positioneringsmethode dat voor een element wordt gebruikt (statisch, relatief, absoluut, vast of plakkerig).
Standaardwaarde: | statisch |
---|---|
geërfd: | Nee |
Animeerbaar: | Nee. Lees over animeren |
Versie: | CSS2 |
JavaScript-syntaxis: | object .style.position="absoluut" |
Browserondersteuning
De getallen in de tabel geven de eerste browserversie aan die de eigenschap volledig ondersteunt.
Property | |||||
---|---|---|---|---|---|
position | 1.0 | 7.0 | 1.0 | 1.0 | 4.0 |
Opmerking: de sticky
waarde wordt niet ondersteund in Internet Explorer of Edge 15 en eerdere versies.
CSS-syntaxis
position: static|absolute|fixed|relative|sticky|initial|inherit;
Eigendomswaarden
Value | Description | Play it |
---|---|---|
static | Default value. Elements render in order, as they appear in the document flow | |
absolute | The element is positioned relative to its first positioned (not static) ancestor element | |
fixed | The element is positioned relative to the browser window | |
relative | The element is positioned relative to its normal position, so "left:20px" adds 20 pixels to the element's LEFT position | |
sticky | The element is positioned based on the user's scroll position
A sticky element toggles between |
|
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
Meer voorbeelden
Voorbeeld
Een element positioneren ten opzichte van zijn normale positie:
h2.pos_left {
position: relative;
left: -20px;
}
h2.pos_right {
position: relative;
left: 20px;
}
Voorbeeld
Meer positionering:
#parent1 {
position: static;
border: 1px solid blue;
width: 300px;
height: 100px;
}
#child1 {
position:
absolute;
border: 1px solid red;
top: 70px;
right: 15px;
}
#parent2 {
position: relative;
border: 1px solid blue;
width: 300px;
height: 100px;
}
#child2 {
position: absolute;
border: 1px solid red;
top: 70px;
right: 15px;
}
Gerelateerde pagina's
CSS-zelfstudie: CSS-positionering
HTML DOM-referentie: eigenschap position