CSS 너비 속성
예시
세 개의 <div> 요소의 너비를 설정합니다.
div.a {
width: auto;
border: 1px
solid black;
}
div.b {
width: 150px;
border: 1px solid black;
}
div.c {
width:
50%;
border: 1px solid black;
}
아래에서 더 많은 "직접 사용해 보기" 예를 살펴보세요.
정의 및 사용
width
속성은 요소의 너비를 설정합니다 .
요소의 너비에는 패딩, 테두리 또는 여백이 포함되지 않습니다!
참고: min -width 및
max-width 속성은 속성을 재정의합니다 width
.
브라우저 지원
표의 숫자는 속성을 완전히 지원하는 첫 번째 브라우저 버전을 지정합니다.
Property | |||||
---|---|---|---|---|---|
width | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
CSS 구문
width: auto|value|initial|inherit;
속성 값
Value | Description | Play it |
---|---|---|
auto | Default value. The browser calculates the width | |
length | Defines the width in px, cm, etc. Read about length units | |
% | Defines the width in percent of the containing block | |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
더 많은 예
예시
백분율 값을 사용하여 <img> 요소의 너비를 설정합니다.
img {
width: 50%;
}
예시
<input type="text"> 요소의 너비를 100px로 설정합니다. 그러나 포커스를 받으면 너비를 250px로 만드십시오.
input[type=text] {
width: 100px;
}
input[type=text]:focus {
width: 250px;
}
관련 페이지
CSS 튜토리얼: CSS 높이 및 너비
CSS 튜토리얼: CSS 상자 모델
CSS 참조: 높이 속성
HTML DOM 참조: 너비 속성