शैली स्थिति संपत्ति
उदाहरण
एक <div> तत्व की स्थिति को सापेक्ष से निरपेक्ष में बदलें:
document.getElementById("myDIV").style.position = "absolute";
परिभाषा और उपयोग
स्थिति गुण किसी तत्व (स्थिर, सापेक्ष, निरपेक्ष या निश्चित) के लिए उपयोग की जाने वाली स्थिति विधि के प्रकार को सेट या लौटाता है।
ब्राउज़र समर्थन
Property | |||||
---|---|---|---|---|---|
position | Yes | Yes | Yes | Yes | Yes |
वाक्य - विन्यास
स्थिति संपत्ति वापस करें:
object.style.position
स्थिति संपत्ति सेट करें:
object.style.position = "static|absolute|fixed|relative|sticky|initial|inherit"
सम्पत्ति की कीमत
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 |
टेक्निकल डिटेल
डिफ़ॉल्ट मान: | स्थिर |
---|---|
प्रतिलाभ की मात्रा: | एक स्ट्रिंग, एक तत्व की स्थिति प्रकार का प्रतिनिधित्व करता है |
सीएसएस संस्करण | सीएसएस 2 |
और ज्यादा उदाहरण
उदाहरण
विभिन्न स्थिति प्रकारों का उपयोग करना:
function myFunction(x) {
var whichSelected = x.selectedIndex;
var posVal = x.options[whichSelected].text;
var elem = document.getElementById("myDiv");
elem.style.position = posVal;
}
उदाहरण
<h2> तत्व की स्थिति लौटाएं:
alert(document.getElementById("myH2").style.position);
संबंधित पृष्ठ
सीएसएस ट्यूटोरियल: सीएसएस पोजिशनिंग
सीएसएस संदर्भ: स्थिति संपत्ति
❮ स्टाइल ऑब्जेक्ट