Stijl positie Eigenschap
Voorbeeld
Verander de positie van een <div> element van relatief in absoluut:
document.getElementById("myDIV").style.position = "absolute";
Definitie en gebruik
De eigenschap position bepaalt of retourneert het type positioneringsmethode dat voor een element wordt gebruikt (statisch, relatief, absoluut of vast).
Browserondersteuning
Property | |||||
---|---|---|---|---|---|
position | Yes | Yes | Yes | Yes | Yes |
Syntaxis
Retourneer de eigenschap position:
object.style.position
Stel de eigenschap position in:
object.style.position = "static|absolute|fixed|relative|sticky|initial|inherit"
Eigendomswaarden
Value | Description |
---|---|
static | Elements renders in order, as they appear in the document flow. This is default. |
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:20" 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 |
Technische details
Standaardwaarde: | statisch |
---|---|
Winstwaarde: | Een String, die het positietype van een element vertegenwoordigt |
CSS-versie | CSS2 |
Meer voorbeelden
Voorbeeld
Verschillende positietypes gebruiken:
function myFunction(x) {
var whichSelected = x.selectedIndex;
var posVal = x.options[whichSelected].text;
var elem = document.getElementById("myDiv");
elem.style.position = posVal;
}
Voorbeeld
Retourneer de positie van een <h2> element:
alert(document.getElementById("myH2").style.position);
Gerelateerde pagina's
CSS-zelfstudie: CSS-positionering
CSS-referentie: eigenschap position
❮ Stijlobject