• 회원가입
  • 로그인
  • 구글아이디로 로그인

[DOM_Style] JS - height 속성 - 요소 높이 설정/반환 (= height속성 = 하이트속성) ※ 요소 세로길이 반환/설정

목차

  1. height 예제 - <button> 요소 높이 설정
  2. height 정의
  3. height 구문
  4. height 예제 - <div> 요소 높이 변경
  5. height 예제 - <img> 요소 너비/높이 변경
  6. height 예제 - <img> 요소 높이 반환

 

height 예제 - <button> 요소 높이 설정

 

<button type="button" id="hz" onclick="homzzang()">클릭</button>


<script>

function homzzang() {

  document.getElementById("hz").style.height = "50px";

}

</script>

 

결과보기

 

height 정의

 

요소 높이 설정/반환

 


 

1. 

  • 높이는 블럭요소 (또는 인라인블럭요소)나 absolute (또는, fixed) 설정된 요소에서만 사용 가능. (※ 인라인요소엔 사용 불가)
  • 내용이 높이 초과 시, overflow 속성으로 내용 제어 가능.

 

2. cf.

width 속성 - 요소 너비 설정/반환.

 

3.

  • 기본값: auto
  • 반환값: 요소 높이 나타내는 문자열
  • CSS버전: CSS1
  • 모든 브라우저 지원.


 

height 구문

 

반환

object.style.height

 

설정

object.style.height = "auto|length|%|initial|inherit"

 


[속성값]

 

auto

브라우저가 높이 자동 설정. (기본값)

 

length

px 등 길이 단위로 높이 지정.

 

%

부모요소 높이의 일정 %로 지정.

 

initial

이 속성의 기본값으로 지정.

 

inherit

부모요소의 속성값 상속.

 

 

height 예제 - <div> 요소 높이 변경

 

<style> 

#hz {width: 300px; height: 100px; background-color: coral; color: white;}

</style>


<button onclick="homzzang()">클릭</button>


<div id="hz">

  <h2>홈짱닷컴 Homzzang.com</h2>

</div>


<script>

function homzzang() {

  document.getElementById("hz").style.height = "200px";

}

</script>

 

결과보기

 

height 예제 - <img> 요소 너비/높이 변경

 

<img id="hz" src="https://i.imgur.com/PQNhCln.gif" width="56" height="56">


<button type="button" onclick="homzzang()">클릭</button>


<script>

function homzzang() {

  document.getElementById("hz").style.height = "100px";

  document.getElementById("hz").style.width = "100px";

}

</script>

 

결과보기

 

height 예제 - <img> 요소 높이 반환

 

<img id="hz" src="https://i.imgur.com/PQNhCln.gif" style="width:56px;height:56px;">


<button type="button" onclick="homzzang()">클릭</button>


<script>

function homzzang() {

  alert(document.getElementById("hz").style.height);

}

</script>

 

결과보기


PS. 높이값이 HTML 속성으로 지정된 경우, 반환 X

<img id="hz" src="https://i.imgur.com/PQNhCln.gif" width="56" height="56">


<button type="button" onclick="homzzang()">클릭</button>


<script>

function homzzang() {

  alert(document.getElementById("hz").style.height);

}

</script>

 

결과보기



분류 제목
DOM_Style JS - emptyCells -
DOM_Style JS - filter 속성 - 이미지필터효과 (= filter속성 = 필터속성) ※ 흑백이미지만들기
DOM_Style JS - flex -
DOM_Style JS - flexBasis -
DOM_Style JS - flexDirection -
DOM_Style JS - flexFlow -
DOM_Style JS - flexGrow 속성 - 동일컨테이너 안 나머지 플렉스아이템에 비해 얼마나 커질지 지정 (= 플렉스…
DOM_Style JS - flexShrink 속성 - 동일컨테이너 안 나머지 플렉스아이템에 비해 얼마나 줄어들지 지정 (= …
DOM_Style JS - flexWrap -
DOM_Style JS - cssFloat 속성 - ★ - 요소나란히 (= 요소한줄로 = 요소가로로 = 요소옆으로정렬 = 플로…
DOM_Style JS - font 속성 ★ - 글자스타일종합 (= font속성 = 글씨체 = 서체 = 글꼴 = 폰트속성, 상…
DOM_Style JS - fontFamily 속성 ★ - 폰트 종류 설정/반환. (= 글꼴 종류 = fontFamily속성 …
DOM_Style JS - fontSize 속성 - 글자크기 (= 폰트크기 = fontSize속성 = 폰트사이즈 속성)
DOM_Style JS - fontStyle 속성 - 글자모양 (= font-style속성 = 글씨체모양 = 글씨모양 = 글자…
DOM_Style JS - fontVariant 속성 - (소문자/보통) 크기의 대문자로 설정/반환.
DOM_Style JS - fontWeight 속성 - 글자굵기 (= font-weight속성 = 폰트굵기 = 글씨체굵기 =글…
DOM_Style JS - fontSizeAdjust -
DOM_Style JS - fontStretch -
DOM_Style JS - hangingPunctuation -
DOM_Style JS - height 속성 - 요소 높이 설정/반환 (= height속성 = 하이트속성) ※ 요소 세로길이 …
5/10
목록
찾아주셔서 감사합니다. Since 2012