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

[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 - minWidth -
DOM_Style JS - navDown -
DOM_Style JS - navIndex 속성 - 요소의 탭 순서를 설정/반환 (= navIndex속성 = 네브인덱스속성)
DOM_Style JS - navLeft -
DOM_Style JS - navRight -
DOM_Style JS - navUp -
DOM_Style JS - objectFit 속성 - 컨테이너에 맞게 <img>/<video> 크기 조정 방법 지정 (= ob…
DOM_Style JS - objectPosition -
DOM_Style JS - opacity 속성 - 요소의 불투명도 설정/반환 (= opacity속성 = 오패서티속성)
DOM_Style JS - order 속성 - 플렉스아이템 나열순서 (= 오더속성 = flex item order속성, IE1…
DOM_Style JS - orphans 속성 - 인쇄페이지 하단 표시할 요소의 최소줄수 설정/반환 (= orphans속성 =…
DOM_Style JS - outline -
DOM_Style JS - outlineColor 속성 - 외곽선두께 (= 아웃라인컬러속성 = outlineColor속성)
DOM_Style JS - outlineOffset -
DOM_Style JS - outlineStyle -
DOM_Style JS - outlineWidth -
DOM_Style JS - overflow 속성 - 범위이탈요소처리 (= 범위넘는요소처리 = 스크롤바 생성 = overflow…
DOM_Style JS - overflowX -
DOM_Style JS - overflowY 속성 ★ - 범위이탈요소처리 (= 범위넘는요소처리 = 스크롤바 생성 = overf…
DOM_Style JS - padding 속성 ★ - 안쪽여백일괄 (= 안여백전체 = 패딩속성 = padding속성) (상속 …
7/10
목록
찾아주셔서 감사합니다. Since 2012