Stil konumu Özellik
Örnek
Bir <div> öğesinin konumunu göreli konumundan mutlak konumuna değiştirin:
document.getElementById("myDIV").style.position = "absolute";
Tanım ve Kullanım
Konum özelliği, bir öğe için kullanılan konumlandırma yönteminin türünü (statik, göreli, mutlak veya sabit) ayarlar veya döndürür.
Tarayıcı Desteği
Property | |||||
---|---|---|---|---|---|
position | Yes | Yes | Yes | Yes | Yes |
Sözdizimi
Pozisyon özelliğini döndürün:
object.style.position
Konum özelliğini ayarlayın:
object.style.position = "static|absolute|fixed|relative|sticky|initial|inherit"
Mülk değerleri
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 |
Teknik detaylar
Varsayılan değer: | statik |
---|---|
Geri dönüş değeri: | Bir öğenin konum türünü temsil eden bir Dize |
CSS Sürümü | CSS2 |
Daha fazla örnek
Örnek
Farklı pozisyon tiplerini kullanma:
function myFunction(x) {
var whichSelected = x.selectedIndex;
var posVal = x.options[whichSelected].text;
var elem = document.getElementById("myDiv");
elem.style.position = posVal;
}
Örnek
<h2> öğesinin konumunu döndürür:
alert(document.getElementById("myH2").style.position);
İlgili Sayfalar
CSS eğitimi: CSS Konumlandırma
CSS referansı: konum özelliği
❮ Stil Nesnesi