Properti lebar gaya
Contoh
Atur lebar elemen <button>:
document.getElementById("myBtn").style.width = "300px";
Definisi dan Penggunaan
Properti lebar menetapkan atau mengembalikan lebar suatu elemen.
Properti lebar hanya berpengaruh pada elemen level blok atau elemen dengan posisi absolut atau tetap. Konten yang meluap dapat dimanipulasi dengan properti overflow.
Tip: Gunakan properti height untuk mengatur atau mengembalikan tinggi elemen.
Dukungan Peramban
Property | |||||
---|---|---|---|---|---|
width | Yes | Yes | Yes | Yes | Yes |
Sintaksis
Kembalikan properti lebar:
object.style.width
Setel properti lebar:
object.style.width = "auto|length|%|initial|inherit"
Nilai properti
Value | Description |
---|---|
auto | The browser sets the width. This is default |
length | Defines the width in length units |
% | Defines the width in % of the parent element |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Detail Teknis
Nilai Bawaan: | mobil |
---|---|
Nilai Kembali: | Sebuah String, mewakili lebar elemen |
Versi CSS | CSS1 |
Lebih Banyak Contoh
Contoh
Ubah lebar elemen <div>:
document.getElementById("myDIV").style.width = "500px";
Contoh
Ubah tinggi dan lebar elemen <img>:
document.getElementById("myImg").style.height = "300px";
document.getElementById("myImg").style.width = "300px";
Contoh
Kembalikan lebar elemen <img>:
alert(document.getElementById("myImg").style.width);
Halaman Terkait
Tutorial CSS: Dimensi CSS
Tutorial CSS: Model Kotak CSS
Referensi CSS: properti lebar
Objek Gaya