이 글은 CSS의 기본 개념을 정리한 글 입니다.
Contents
- CSS 정의
- CSS 속성
- CSS 선택자
- CSS 단축 속성
[ 필수 ]
[ 선택 ]
배우기는 쉽지만 고유의 복잡함을 가지고 있기 때문에 이를 해결하기 위한 다양한 방법론들이 만들어졌다.
display
position
float
** clear:both
를 사용
padding & margin
border
box-sizing
overflow
font
* { margin: 0; padding: 0; box-sizing: border-box; }
div { color : red; }
.class { color : red; }
#id { color : red; }
input[type="text"] { color : red; }
.class, #id { background-color: blue; }
id | class |
---|---|
#으로 선택 | .으로 선택 |
한 문서에 단 하나의 요소에만 적용 | 동일한 값을 갖는 요소 많음 |
특정 요소에 이름을 붙이는 데 사용 | 스타일의 분류(classification)에 사용 |
box-sizing : content-box ⇒ padding, border를 제외한 컨텐츠 자체 사이즈를 지정
현재 상태에 대한 포커스
button { font-size: 14px; }
/* :hover */
button:hover { background-color: red; }
/* :not, disabled */
button:not(:disable):hover { background-color: blue; }
/* :focus */
button:focus { background-color: orange; }
/* :active */
button:active { background-color: yellow; }
/* :checked */
ol {
li {
/* li의 세번째 그 후에 오는 형제 li 모두 선택 */
&:nth-child(3) ~ li {
color: grey;
}
&:only-child {}
}
}
임의로 요소가 가상으로 존재하는 것처럼 사용함
span {
display: block; width: 100px; height: 100px;
/* ::before */
&::before { content: "(" }
/* ::after */
&::after { content: ")" }
}
padding: 100px;
padding: 100px 80px;
padding: 100px 80px 100px;
{ padding: 100px 80px 100px 80px; }
font-style: italic;
font-weight: bold;
font-size: .8em;
line-height: 1.2;
font-family: Arial, sans-serif;
/* 단축 */
font: italic bold .8em/1.2 Arial, sans-serif;
border-width : 1px;
border-style: solid;
border-color: #000;
/* 단축 */
border: 1px solid #000
background-color: #000;
background-image: url(images/bg.gif);
background-repeat: no-repeat: no-repeat;
background-position: top right;
/* 단축 */
background: #000 url(image/bg.gif) no-repeat top right;