Stylposisie Eiendom _
Voorbeeld
Verander die posisie van 'n <div> element van relatief na absoluut:
document.getElementById("myDIV").style.position = "absolute";
Definisie en gebruik
Die posisie-eienskap stel of gee die tipe posisioneringsmetode wat vir 'n element gebruik word (staties, relatief, absoluut of vas) terug.
Blaaierondersteuning
Property | |||||
---|---|---|---|---|---|
position | Yes | Yes | Yes | Yes | Yes |
Sintaksis
Gee die posisie eiendom terug:
object.style.position
Stel die posisie-eienskap:
object.style.position = "static|absolute|fixed|relative|sticky|initial|inherit"
Eiendomswaardes
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 |
Tegniese besonderhede
Standaard waarde: | staties |
---|---|
Terugkeerwaarde: | 'n String, wat die posisietipe van 'n element voorstel |
CSS weergawe | CSS2 |
Meer voorbeelde
Voorbeeld
Gebruik verskillende posisietipes:
function myFunction(x) {
var whichSelected = x.selectedIndex;
var posVal = x.options[whichSelected].text;
var elem = document.getElementById("myDiv");
elem.style.position = posVal;
}
Voorbeeld
Gee die posisie van 'n <h2> element terug:
alert(document.getElementById("myH2").style.position);
Verwante bladsye
CSS-tutoriaal: CSS-posisionering
CSS verwysing: posisie eiendom
❮ Stylvoorwerp