Wysokość stylu Właściwość
Przykład
Ustaw wysokość elementu <button>:
document.getElementById("myBtn").style.height = "50px";
Definicja i użycie
Właściwość height ustawia lub zwraca wysokość elementu.
Właściwość height ma wpływ tylko na elementy blokowe lub na elementy z bezwzględną lub stałą pozycją. Przepełnioną treścią można manipulować za pomocą właściwości overflow.
Porada: Użyj właściwości width , aby ustawić lub zwrócić szerokość elementu.
Obsługa przeglądarki
Property | |||||
---|---|---|---|---|---|
height | Yes | Yes | Yes | Yes | Yes |
Składnia
Zwróć właściwość wysokości:
object.style.height
Ustaw właściwość wysokości:
object.style.height = "auto|length|%|initial|inherit"
Wartości nieruchomości
Value | Description |
---|---|
auto | The browser sets the height. This is default |
length | Defines the height in length units |
% | Defines the height 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 |
Szczegóły techniczne
Domyślna wartość: | automatyczny |
---|---|
Wartość zwrotu: | String, reprezentujący wysokość elementu |
Wersja CSS | CSS1 |
Więcej przykładów
Przykład
Zmień wysokość elementu <div>:
document.getElementById("myDIV").style.height = "500px";
Przykład
Zmień wysokość i szerokość elementu <img>:
document.getElementById("myImg").style.height = "300px";
document.getElementById("myImg").style.width = "300px";
Przykład
Zwróć wysokość elementu <img>:
alert(document.getElementById("myImg").style.height);
Powiązane strony
Samouczek CSS: wymiar CSS
Samouczek CSS: model Box CSS
Odniesienie CSS: właściwość wysokości
❮ Obiekt stylu