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

[box] CSS - box-sizing 속성 ★★ - 너비결정방식 (= 길이결정방식 = box-sizing속성 = 박스사이징속성) ※ 요소너비 결정방식 ※ 요소실제너비

목차
  1. box-sizing 예제 - 요소 너비 계산 방식 선택
  2. box-sizing 정의
  3. box-sizing 구문
  4. box-sizing 예제 - <input>요소와 <button> 요소 높이 통일

 

box-sizing 예제 - 요소 너비 계산 방식 선택 

 

<style> 

#hz_cb h2 {color:blue;}

#hz_cb div {

    box-sizing: content-box  /* 요소너비 = width + padding + border */

    width: 400px;

    height: 100px;

    padding: 30px;    

    border: 10px solid blue;

}


#hz_bb h2 {color:red;}

#hz_bb div {

    box-sizing: border-box;  /* 총너비 = width */

    width: 400px;

    height: 100px;

    padding: 30px;    

    border: 10px solid red;

}

</style>

</head>

<body>


<div id="hz_cb">

  <h2>box-sizing: content-box (기본값)</h2>

  <p>padding, border : 총너비에 포함 O</p>

  <div>

    총너비 480px = width 400 + padding (30 x 2) + border (10 x 2)<br>

    홈짱닷컴 (Homzzang.com)

  </div>

</div>

  

<div id="hz_bb">

  <h2>box-sizing: border-box</h2>

  <p>padding, border : 총너비에 포함 X</p>

  <div>

    총너비 400px = width 400<br>

    홈짱닷컴 (Homzzang.com)

  </div>

</div>


결과 보기

 

box-sizing 정의

 

(박스너비 = 박스전체너비 =박스총너비) 결정방식.

즉, 

너비・높이 계산 시, padding・ border 포함여부 결정.

 


 

1.

  • 기본값: content-box
  • 상속여부: X
  • 애니효과: X
  • CSS버전: CSS3
  • JS구문: object.style.boxSizing="border-box"

 

2.

IE8 이상 주요 최신브라우저 지원. (※ 구형 브라우저 경우, 접두사 필요)

  • 구형 Chrome, Safari 경우: -webkit-
  • 구형 Firefox 경우: -moz-

 

 

box-sizing 구문

 

selector {box-sizing: content-box|border-box|initial|inherit;}

 


[속성값]

 

content-box

너비 = (width + 좌우border + 좌우padding)

  • <input type="text">와 <button> 요소 높이 같게 할 때 필요.

 

border-box

너비 = (width)

  • 실제 너비: width + 좌우margin
  • padding, border 값은 너비에서 제외.

 

initial

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

 

inherit

부모요소의 속성값 상속.

 

 

box-sizing 예제 - <input>요소와 <button> 요소 높이 통일

 

<style>

.display {float:left; height:30px;line-height:30px; box-sizing: content-box;}

.btn_box {position:relative;}

.btn_box .btn  {width:80px; height:30px; line-height:30px; box-sizing: content-box; overflow:hidden;}

.btn_box .hidden {font-size:29px; position:absolute; right:0px; top:0px; opacity:0; filter: alpha(opacity=0); -ms-filter: alpha(opacity=0); cursor:pointer;}

</style>


<input type="text" id="hz" class="display" readonly>

<div class="btn_box">

    <button type="button" class="btn">파일찾기</button>

    <input type="file" name="hz" class="hidden" onchange="javascript: document.getElementById('hz').value = this.value"/>

</div>

 

결과보기

PS. 주의: box-sizing:content-box 없으면, 높이값이 같아도 실제 높이 다름.



분류 제목
border CSS - border-style 속성 ★ - 테두리모양일괄 (= border-style속성 = 보더스타일속…
box CSS - padding 속성 ★ - 안쪽여백 (= padding속성 = 패딩속성)
box CSS - min-height 속성 - 최소높이 (= 최소세로길이 = min-height속성 = 민하이트속성…
outline CSS - outline-style (아웃라인스타일) - 테두리 외곽 스타일 (상속 X) : (IE8)
intro CSS - @charset 구문 - 스타일시트 인코딩방식 설정 (= 언어셋지정/문자셋지정 = @charset…
selector CSS - :last-child 가상선택자 - 그 부모의 마지막자식요소인 지정요소 (= :last-child…
border CSS - border-left 속성 - 테두리좌측일괄 (= 테두리왼쪽일괄 = border-left속성 = …
selector CSS - :lang() 가상선택자 - 특정언어속성요소 (= 언어선택자 = 랭선택자, IE8)
list CSS - list-style-position 속성 ★ - 리스트 스타일 위치 (= 리스트 마커 위치 = …
box CSS - max-height 속성 - 최대높이 (= 최대세로길이 = max-height속성 = 맥스하이트속…
selector CSS - element>element 자식선택자 ★ - 직접 자식요소만 선택. (요소선택자, IE7)
text CSS - writing-mode 속성 - 텍스트 방향 가로/세로 제어. (= 글쓰기 방향 = 쓰기 모드 제…
animation CSS - animation-iteration-count 속성 - 애니반복횟수 (= 움직임반복횟수, IE10…
func CSS - hsl() 함수 - (색조, 채도, 밝기)로 색상 정의. (= hsl함수 = 에이치에스엘함수/흐슬…
border CSS - border 속성 ★ - 테두리일괄 (= border속성 = 보더속성) (상속X)
background CSS - background-attachment 속성 - 배경이미지 고정 (= background-atta…
selector CSS - :nth-child() 가상선택자 ★ - 그 부모의 n번째 자식요소 (=nth-child선택자 =…
background CSS - background 속성 ★ - 배경 일괄 (= background속성 = 백그라운드속성)
animation CSS - animation-direction 속성 - 애니방향 (= 움직임방향 = 애니메이션디렉션속성, I…
responsive CSS - Responsive Image - (반응형 이미지) ★★★
22/27
목록
찾아주셔서 감사합니다. Since 2012