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

[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 없으면, 높이값이 같아도 실제 높이 다름.



분류 제목
text CSS - word-wrap 속성 ★ - 단어줄바꿈 위해 긴단어쪼개기 (= 긴단어깨기 = 긴단어나누기 = w…
responsive CSS - RES Frameworks - (반응형 프레임워크) - 반응형홈페이지틀
outline CSS - outline-color 속성 - 외곽선두께 (= 아웃라인컬러속성 = outline-color속성…
outline CSS - outline-width (아웃라인위드스) - 테두리 외곽 두께 (상속 X) : (IE8)
selector CSS - :empty 가상선택자 - 자식/내용 없는 텅 빈 요소 선택 (= :empty선택자 = 엠프티 선…
box CSS - box-sizing 속성 ★★ - 너비결정방식 (= 길이결정방식 = box-sizing속성 = 박…
animation CSS - animation 속성 ★ - 애니메이션 단축속성 (= animation속성 = 애니메이션속성, …
selector CSS - ::first-line 가상선택자 - 요소의 첫번째라인 선택 (= ::first-line선택자 =…
css CSS - pointer-events 속성 - 마우스이벤트에 대한 반응 여부 (= pointer-events…
text CSS - overflow-wrap 속성 - 줄바꿈 위해 단어 쪼개기 (= overflow-wrap속성 = …
image CSS - enter an Image (이미지 가운데정렬/중앙정렬)
css CSS - 인스타그램(instagram) 배경색 효과
shadow CSS - text-shadow 속성 - 글자 그림자/음영 효과 주기 (= text-shadow속성 = 텍스…
selector CSS - ::selection 가상선택자 - 사용자가 선택한 영역 (= ::selection선택자) (가상…
background CSS - background-size 속성 ★ - 배경이미지 크기 (background-size속성 = 백…
selector CSS - [attribute|=value] 속성선택자 - 해당속성값 또는 뒤에 하이픈 연결된 속성값 보유 …
box CSS - padding-bottom 속성 - 안쪽여백하단 (= padding-bottom속성 = 패딩바텀속…
selector CSS - [attribute*=value] 속성선택자 - 지정 속성값 문자열 포함 모든 요소 (IE7)
text CSS - text-decoration-line 속성 - 텍스트라인위치종류 (= text-decoration…
text CSS - text-align-last 속성 - 단락마지막라인정렬 (= text-align-last속성 = …
18/27
목록
찾아주셔서 감사합니다. Since 2012