CSS는 웹에 적용할 스타일을 적어둔 일종의 스타일 명세서
선언 블록(Declaration Block): 선택자 뒤에 위치한 {}
(중괄호) 안의 한 블록 또는 덩어리
선언(Declaration): CSS에서 프로퍼티와 값의 짝
<h1>
, <p>
, <div>
와 같은 일반적인 태그 이름을 선택자로 사용CSS에서는 ,
(콤마)로 선택자 여러 개의 스타일을 한꺼번에 지정
h1, p {
color: red;
}
px:
pixel이라는 단위 1920X1080가 바로 픽셀 수
CSS에서 쓰는 1px은 정해진 절대 길이로 쓰인다
e**m
은 현재 스타일이 지정되는 요소의 폰트 크기를 기준**rem
은 최상위 요소의 폰트 크기를 기준em
과 rem
은 다음과 같은 계산방식으로 계산 <div id="main">
단위
<div id="per">per</div>
</div>
html {
background-color: skyblue;
font-size: 32px;
}
#main {
background-color:bisque;
width: 50%;
}
#per {
background-color: blue;
width: 50%;
}
#main
의 경우 html
의 50%
너비만큼 가지고, 다시 #per
의 경우 #main
을 기준으로 50%
를 가진다. %
는 기준이 되는 상위 요소의 font-size
를 기준으로 하지 않고 너비, 높이, 폰트 크기 등 각각의 프로퍼티 값의 상대적인 값을 가진다.font-size
가 18px
이고 해당 요소의 font-size
가 50%
면, 해당 요소의 font-size
는 9px
이 된다..box {
width: 200px;
height: 100px;
background-color: blue;
}
.box {
width: 200px;
height: 100px;
background-color: rgb(102, 205,170)
}
.box {
width: 200px;
height: 100px;
background-color: #F08080;
}
.box {
width: 200px;
height: 100px;
background-color: rgba(102, 205, 170, 0.5);
}
.box {
width: 200px;
height: 100px;
background-color: #F0808055;
}
p {
color: red;
}
p {
color: red;
}
#goorm {
background-color: blue;
}
<p>
태그 중에서 해당하는 아이디를 가진 요소만 배경이 파란색으로 바뀜<p>사회자</p>
<p class="mafia">마피아</p>
<p class="citizen">시민</p>
<p class="mafia">마피아</p>
<p>경찰</p>
<p class="citizen">시민</p>
<p class="citizen">시민</p>
.mafia {
color: white;
background-color: black;
}
.citizen {
color: white;
background-color: green;
}
*
를 입력* {
color: yellow;
}
[]
(대괄호)로 속성과 속성 값을 넣어 작성선택자[속성명="속성값"] {
color: red;
}
<div>
안에 포함되는 하위 요소인 <p>
는 <div>
의 자식 요소(Child Element)<div>
의 상위 요소인 article
은 <div>
의 부모 요소(Parent Element) <article>
부모 요소
<div>
나
<div>자식 요소 1</div>
<p>자식 요소 2</p>
<div>자식 요소 3</div>
</div>
</article>
<div>
의 하위에 있는 <div>
, <p>
는 모두 자식 요소 >
(꺽쇠)를 써준다선택자A > 선택자B {
color: green;
}
<article>
부모 요소
<div id="me">
나
<div>자식 요소 1
<p>후손 요소 1</p>
</div>
<p>자식 요소 2</p>
<div>자식 요소 3
<p>후손 요소 2</p>
</div>
</div>
</article>
#me > p {
background-color: green;
}
div > p
라고 사용하면 div > p
라는 구조를 가진 모든 요소에 스타일이 적용div > p {
background-color: green;
}
선택자A 선택자B {
background-color: yellow;
}
#me
의 하위에 있는 모든 <p>
태그가 선택#me p {
background-color: yellow;
}
선택자:pseudo-class{
color: red;
}
제목 없음200 X 100
의 사이즈를 가지는 컨텐츠 박스 두 개가 위 아래로 배치되어 있음을 확인<div id="main">
<div class="inner">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Obcaecati labore doloribus quod nulla earum facilis, fugiat culpa, modi accusantium iste ea quidem repellat omnis, quia totam repudiandae atque. Distinctio, quae!
</div>
<div class="inner">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Obcaecati labore doloribus quod nulla earum facilis, fugiat culpa, modi accusantium iste ea quidem repellat omnis, quia totam repudiandae atque. Distinctio, quae!
</div>
</div>
body { background-color: skyblue; }
.inner {
background-color: pink;
width: 200px;
height: 100px;
}
200 X 100
보다 크더라도, 컨텐츠 박스를 기준으로 배치가 된다(마진, 패딩 등이 없는 경우).border-style
은 말 그대로 선의 스타일로, 선의 종류를 지정하는 프로퍼티, 원하는 모양의 경계선을 추가할 수 있다.border-style: none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset | initial | inherit
border-width
와 border-color
를 이용하여 선의 두께와 색을 지정border-style
없이 지정했을 땐 적용되지 않습니다.border: red solid 1px;
border-bottom: red solid 1px;
border-radius
는 테두리 존재 여부와 별개로 전체 background
에 적용.radius {
border-top-left-radius: 24px 12px;
}
/
로 구분하여 차례대로 작성border-radius: 가로 반지름 / 세로 반지름;
content-box
의 width
값은 컨텐츠만의 사이즈border-box
는 컨텐츠의 크기와 패딩까지 합한 값 box-sizing: content-box;
width(height) = content size
box-sizing: border-box;
width(height) = content size + padding + border size
font-family
를 통해 원하는 폰트의 종류를 지정font-family: '폰트이름1' '폰트이름2';
/* ✅ 올바른 한 단어 폰트 이름 */
font-family : Arial;
/* ✅ 올바른 한 단어 폰트 이름 */
font-family : 'Arial';
/* ❌ 잘못된 두 단어 이상 폰트 이름 */
font-family : Cute Font;
/* ✅ 올바른 두 단어 이상 폰트 이름 */
font-family : 'Cute Font';
/* ❌ 잘못된 하이픈(-)이 들어간 폰트 이름 */
font-family : Noto-sans;
/* ✅ 올바른 하이픈(-)이 들어간 폰트 이름 */
font-family : 'Noto-sans';
font-family
를 통해 폰트의 종류를 정의할 때는 여러 개를 동시에 지정하는 경우가 많다. 모든 이용자의 기기에 동일한 폰트가 없을 수도 있기 때문에 폰트를 여러 개를 지정하여 앞 순서에 위치한 폰트부터 차례로 적용. 첫 번째 폰트가 없으면 두 번째 폰트를 적용하는 방식/* Cute Font가 없는 경우 Arial 적용 */
font-family : 'Cute Font', Arial, cursive;
/* ❌ ✅ */
normal
은 말 그대로 기본 값italic
은 이텔릭체가 디자인되어 있는 폰트에서 사용oblique
는 이텔릭체 디자인이 없더라도 무조건 글자를 기울여서 표현font-weight
는 폰트 굵기를 지정할 때 사용bold
혹은 100 단위의 숫자 값 등을 사용normal
폰트가 400
, bold
폰트가 700
의 값을 가집니다./* 아래의 두 결과는 동일 */
font-weight: 400;
font-weight: normal;
/* 아래의 두 결과는 동일 */
font-weight: 700;
font-weight: bold;
font-style
, font-weight
, font-size
, font-family
를 순서대로 띄어쓰기로 구분하여 작성/* ✅ font: font-style font-weight size font-family */
font: italic bold 24px 'Nanum Pen Script', cursive;
/* ✅ font: size font-family */
font: 24px 'Nanum Pen Script', cursive;
text-align
프로퍼티는 텍스트를 편집할 때 꽤 자주 사용되는 텍스트 좌, 우, 중앙 정렬left
, center
, right
를 사용<div id="up">
#up
<p>#up > p 오른쪽 정렬</p>
</div>
<div id="down">
#down
<p>#down > p 오른쪽 정렬</p>
</div>
p {
text-align: right;
background-color: pink;
}
#up {
background-color: skyblue;
width: 100%;
height: 200px;
}
#down {
background-color: lemonchiffon;
width: 50%;
height: 200px;
}
#up > p {
width: 80%;
}
#down > p {
width: 50%;
}
아래와 같이 모두 부모 요소나 웹의 크기와 상관 없이 text-align
이 적용된 해당 요소(#down > p
, #up > p
)를 기준으로 정렬된 것을 확인
justify
라는 값은 좌우로 띄어쓰기를 늘려 붙입니다.
line-height
는 문장 사이의 간격을 조정하는 프로퍼티line-height
는 px
와 같이 단위가 존재하는 값 또는 단위가 없는 숫자 값으로 높이를 조정line-height
는 line 사이의 height가 아닌 말 그대로 line의 height를 뜻합니다. letter-spacing
은 자간, 즉 각 글자 사이의 간격을 조정text-indent
는 문단의 시작부에 들여쓰기를 지정display
는 요소가 보여지는 방식을 지정하는 프로퍼티display:block
을 가지고 있는 요소는 항상 새로운 줄에서 시작하며, 따로 너비를 지정하지 않아도 width:100%
을 기본 값으로 갖습니다.div
, h1
~h6
, p
, header
, footer
, section
등이 이에 해당display:inline
을 가지고 있는 inline
요소는 block
과 달리 새로운 줄에서 시작하지 않으며 필요한 만큼의 너비만 가집니다.span
, a
, img
등이 이에 해당display:block
예시<!-- display: block; 📦-->
<h1>h1 태그</h1>
<div>div 태그</div>
<p>p 태그</p>
<article>article 태그</article>
<li>li 태그</li>
<!-- display: inline; 📏 -->
<strong>strong 태그</strong>
<span>span 태그</span>
<a href="/">a 태그</a>
h1, div, p, article, li {
background-color: pink;
}
strong, span, a {
background-color: skyblue;
}
block
에 해당하는 요소의 경우 그대로 유지됐지만, inline
에 해당하는 요소는 한 줄에 차례대로 출력 h1
, div
등 block
값을 기본으로 가지는 요소들을 보면 옆에 다른 요소들이 올 수 없도록 혼자 한 줄을 차지하며 '막고' 있다. 아래와 같이 두 요소가 한 줄에 함께 놓일 수 있음에도 불구하고 요소의 크기에 상관 없이 그 어느 요소도 한 줄에 함께 배치될 수 없다. display:block
의 경우 요소 컨텐츠의 width
가 100%
값을 가지고 있다. 하지만, 크기를 직접 지정하면 자동으로 남은 길이를 margin
으로 채워 옆으로 다른 요소가 오는 것을 막는다. display:inline
예시<p class="box display_block">display: block;</p>
<span class="box display_inline">display: inline;</span>
.display_block {
background-color: pink;
margin: 0;
width: 100px;
}
.display_inline{
background-color: skyblue;
}
strong
, span
, a
태그가 한 줄에 놓여 있는 것을 확인 inline
의 경우 요소의 컨텐츠 크기에 한정된 크기를 가지며, 부모의 너비 안에서 한 줄에 들어갈 수 있는 만큼 일렬로 배치block
은 전체 문단과 같이 큰 맥락을 가질 때 사용하는 반면, inline
은 그 안에 들어가는 단어, 링크, 이미지 등에 쓰인다. block
의 경우 width
, height
, margin
, padding
을 모두 사용할 수 있다inline
은 width
, height
, margin-top
, margin-bottom
프로퍼티를 지정할 수 없다inline-block
은 block
과 inline
요소의 특징을 모두 가집니다.inline
과 동일하지만 사용할 수 없었던 width
, height
, margin-left
, margin-right
을 지정 제목 없음display:none
으로 설정하면 브라우저에 해당 요소가 출력되지 않습니다.position
값은 static
이 기본static
에서는 좌표 프로퍼티를 사용할 수 없다div 2
에 position: relative
의 top
, left
에 각각 16px
를 할당하면 아래와 같이 position: static
이 가질 위치보다 위에서 16px
, 왼쪽에서 16px
만큼 멀어지게 된다.
relative
, absolute
혹은 fixed
가 선언된 곳을 기준으로 좌표 프로퍼티가 작동<div class="parent">
<div class="box absolute">display: absolute;</div>
</div>
body {
background-color: skyblue;
}
.box {
width: 100px;
height: 50px;
}
.parent {
border: 2px solid red;
width: 200px;
height: 100px;
position: relative;
}
.absolute {
background-color: pink;
position: absolute;
bottom: 16px;
right: 16px;
}
.parent
에 position: relative
가 선언되었기 때문에 .parent
를 기준으로 bottom
과 right
가 적용
.parent
를 감싸는 <div>
태그를 하나 더 만들고 .ancestor
에 position:relative
를 적용하면 차이가 발생
<div class="ancestor">
<div class="parent">
<div class="box absolute">display: absolute;</div>
</div>
</div>
body {
background-color: skyblue;
}
.box {
width: 100px;
height: 50px;
}
.ancestor {
border : 2px solid green;
width: 400px;
height: 200px;
position: relative;
}
.parent {
border: 2px solid red;
width: 200px;
height: 100px;
}
.absolute {
background-color: pink;
position: absolute;
bottom: 16px;
right: 16px;
}
.ancestor
를 기준으로 .absolute
가 배치
만약 부모나 조상 프로퍼티에 relative
, absolute
, fixed
가 없다면 최상단 태그인 <body>
를 기준으로 위치가 지정
z-index
를 통해 수직으로 어떻게 쌓이는지 정하는 프로퍼티로, 값은 숫자로 표현static
을 제외한 요소에서만 적용 float
****프로퍼티는 말 그대로 요소를 어떻게 띄울지 결정float
프로퍼티는 요소를 디자인 흐름에서 벗어나게 한 뒤, 사용자가 지정한 방향에 배치하도록 하는 프로퍼티float
가 없을 때와 다르게 이미지의 파란 선과 노란 선이 같은 점에서 시작하고, 이는 마치 이미지주위를 .text
가 감싸는 것처럼 보인다. flex-direction
으로 flex container 안에서 flex item이 배치될 기본 방향을 정할 수 있다.row
라는 값으로 기본 설정되며 item은 왼쪽에서 오른쪽으로 정렬.container {
background-color: skyblue;
padding: 16px;
display: flex;/* flex container에 해당하는 부분에 display: flex를 작성 */
}
.container
에 flex-direction: column
을 추가하면 item이 세로 방향으로 정렬.container {
background-color: skyblue;
padding: 16px;
display: flex;
flex-direction: column; /* column은 세로방향, row는 가로방향 */
}
flex-direction
의 값으로 row
, column
이외에 row-reverse
와 column-reverse
를 사용row
와 column
의 역순으로 item을 정렬.container {
background-color: skyblue;
padding: 16px;
display: flex;
flex-direction: row-reverse; /* column-reverse 세로 역방향, row-reverse는 가로 역방향 */
}
flex-wrap: wrap
을 이용하면 item이 다음 줄로 넘어가도록 할 수 있다..container {
background-color: skyblue;
padding: 16px;
display: flex;
flex-direction: row;
width: 200px;
flex-wrap: wrap;
}
flex-wrap
을 따로 지정하지 않으면 기본 값으로 nowrap
이 설정.container {
background-color: skyblue;
padding: 16px;
display: flex;
flex-direction: row;
width: 200px;
flex-wrap: nowrap; /* flex-wrap의 기본값 */
}
nowrap
으로 지정하면 모든 item이 한 줄에 출력flex-direction
이 column
인 경우.container {
background-color: skyblue;
padding: 16px;
display: flex;
flex-direction: column;
height: 100px;
flex-wrap: wrap;
}
flex-direction
과 flex-wrap
은 flex-flow
로 한번에 지정할 수 있다.flex-flow
의 값으로 direction
과 wrap
을 순서대로 써주면 된다..container {
background-color: skyblue;
padding: 16px;
display: flex;
height: 100px;
flex-flow: column wrap;
/* 아래와 동일
flex-direction: column;
flex-wrap: wrap;
*/
}
justify-content
는 flex-direction
으로 정해진 방향에 flex item들을 어떻게 정렬할 것인지 결정 flex-start
, center
, flex-end
는 flex-direction
이 row
일 때 왼쪽 끝, 가운데, 오른쪽 끝을 기준으로 정렬 flex-direction
이 column
면 flex-start
, center
, flex-end
는 위 끝, 가운데, 아래 끝을 기준으로 정렬 space-between
은 시작과 끝에 item을 하나씩 두고 그 사이 남은 공간을 동일한 간격으로 나눠 나머지 item을 배치space-around
는 시작과 끝을 기준으로 하여 item들을 동일한 간격으로 배치 align-items
는 item을 flex-direction
에서 정해진 방향의 수직방향으로 정렬 align-items
는 기본값으로 stretch
를 갖는데, 이는 별다른 크기가 지정되지 않았을 때 flex 아이템을 늘려서 맞춰줍니다..item {
border: pink 4px solid;
background-color: #fff;
text-align: center;
}
.container {
background-color: skyblue;
height: 200px;
display: flex;
}
.item
에 따로 높이를 지정해 주지 않았지만 자동으로 부모 요소의 크기만큼 늘어나 있다. .align-items
의 기본값인 stretch
가 적용되었기 때문
align-items: flex-start
를 추가하면 높이가 콘텐츠의 크기만큼으로 바뀌는 것을 확인
.container {
background-color: skyblue;
height: 200px;
display: flex;
align-items: flex-start;
}
flex-start
는 수직이 시작하는 부분부터 정렬flex-end
는 수직이 끝나는 부분부터 정렬center
는 가운데 위치에 정렬 baseline
을 값으로 가지면 글꼴의 기준선인 baseline
을 기준으로 flex item들을 정렬baseline
을 기준으로 맞춘다.align-items
에 baseline
을 적용하면 아래 그림처럼 각각의 박스 내에 있는 숫자 글꼴의 기준선을따라 박스들이 세로축으로 이동하며 정렬 baseline
속성이 적용되지 않는다. baseline
이 가로축에서의 글꼴 기준선을 기준으로 정렬하기 때문align-content
는 flex item들이 여러 줄일 경우 flex-direction
방향을 기준으로 수직 정렬 방법을 결정stretch
며, flex-start
, center
, flex-end
속성은 align-items
와 비슷 align-content
를 쓰기 위해서는 flex-wrap: wrap
이 꼭 포함wrap
이 없다면 align-content
가 적용되지 않는다.box {
width: 96px;
height: 48px;
background-color: #fff;
border: 4px solid pink;
text-align: center;
box-sizing: border-box;
padding: 8px;
}
.container {
display: flex;
width: 400px;
height: 200px;
flex-wrap: wrap; /* align-content를 위해서는 반드시 필요 */
}
.row {
background-color: skyblue;
flex-direction: row;
}
.column {
background-color: lemonchiffon;
flex-direction: column;
}
.start {
align-content: flex-start;
}
.center {
align-content: center;
}
.end {
align-content: flex-end;
}
flex-wrap: wrap
으로 item이 여러 줄에 걸쳐지게 된 이 상태에서 align-content
가 아닌 align-items
일 경우.start {
align-items: flex-start;
}
.center {
align-items: center;
}
.end {
align-items: flex-end;
}
align-content
의 경우 여러 줄에 걸친 item들이 한 몸처럼 움직이고, align-items
의 경우 각 줄이 따로 나뉘어 정렬
space-between
은 수직 방향으로 끝과 끝에 하나씩 기준을 두고 그 사이에 배치하며, space-around
는 모든 간격을 동일하게 배치 display: flex
가 적용된 부모 요소의 자식 요소에만 사용.container {
background-color: skyblue;
height: 36px;
padding: 12px;
margin-bottom: 16px;
display: flex;
}
.item {
display: flex;
justify-content: center;
align-items: center;
border: 1px solid #fff;
background: pink;
flex-grow: 1;
}
.target {
background-color: lemonchiffon;
flex-grow: 2;
}
.none {
background-color: grey;
flex-grow: 0;
}
flex-grow
의 값이 1 이상인 flex item이 여러 개라면 flex-grow
값에 따라 flex container의 크기를 나눠 가진다. 마지막 줄의 경우 1:2:1의 비율로 크기를 나눠 가짐
flex-grow
크기는 비율이기 때문에 flex container의 크기가 커지거나 줄어들면 동일한 비율로 크기가 커지거나 줄어든다.
flex-grow
는 flex item의 확장을 정의
flex-grow
와 달리 1<div class="container none">
<div class="item">0</div>
<div class="item">0</div>
<div class="item">0</div>
</div>
<div class="container active">
<div class="item">1</div>
<div class="item">1</div>
<div class="item">1</div>
</div>
<div class="container target">
<div class="item">1</div>
<div class="item">3</div>
<div class="item">5</div>
</div>
.container {
background-color: skyblue;
height: 36px;
padding: 12px;
margin-bottom: 16px;
display: flex;
width: 400px;
}
.item {
/* 텍스트 가운데 정렬을 위한 스타일*/
width: 200px;
display: flex;
justify-content: center;
align-items: center;
border: 1px solid #fff;
background: pink;
}
.none > .item {
flex-shrink: 0;
}
.active > .item {
flex-shrink: 1;
}
.target > .item:first-child {
flex-shrink: 1;
}
.target > .item:nth-child(2) {
flex-shrink: 5;
}
.target > .item:last-child {
flex-shrink: 3;
}
첫 번째 줄과 같이 flex-shrink: 0
인 경우 flex item은 작아지지 않기 때문에 flex container를 벗어나게 된다.
flex-shrink: 1
인 경우 flex item은 flex container에 맞춰 줄어든다.
마찬가지로 flex-shrink
의 값은 비율이기 때문에 flex container가 줄어들면 각 flex item에 적용한 값을 기준으로 비율에 맞춰 줄어든다.
flex container를 줄여보기 위해 아래와 같이 .container
에서 width: 400px
을 지워본 경우
.container {
background-color: skyblue;
height: 36px;
padding: 12px;
margin-bottom: 16px;
display: flex;
}
flex-basis
는 flex item의 기본 크기를 결정하며, 기본값은 auto
auto
로 값이 설정되면 원래 컨텐츠의 크기가 할당flex-basis
의 값이 auto
라면 각 flex item의 크기가 flex-basis
로 할당flex-grow
에 따라 2:1의 비율로 나눔 flex-basis
의 값이 0
이면 flex-grow
에 따라 각 flex item의 크기가 2:1:1 비율로 나눔 flex-basis
의 값이 100px인 경우(수치를 값으로 가지는 경우) 각 컨텐츠마다 100px
300px
에 해당하는 값을 제외한 크기를 2:1:1의 비율로 나눔![Untitled](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/606eb80c-d91f-407c-9729-aeee2bc91d44/Untitled.png)
flex-grow
, flex-shrink
, flex-basis
를 한번에 설정할 수 있는 축약형flex
를 작성할 때는 flex-grow
, flex-shrink
, flex-basis
의 순서로 값을 넣어야 한다.flex-grow: 1;
flex-shrink: 0;
flex-basis: 400px;
/* 위와 아래는 동일한 코드 */
flex: 1 0 400px;
flex: 1
혹은 flex: 0
과 같이 값도 축약하여 사용할 수 있다flex-grow: 1;
flex-shrink: 1;
flex-basis: 0%;
/* 위와 아래는 동일한 코드 */
flex: 1;
flex-grow: 0;
flex-shrink: 1;
flex-basis: 0%;
/* 위와 아래는 동일한 코드 */
flex: 0;
flex
의 값으로 단위가 없는 값이 주어질 경우 flex-grow
와 동일하다고 볼 수 있다.flex-shrink
의 경우 기본값인 1
이 할당flex-basis
는 축약형에서는 0
으로 할당<div class="grid-container">
<header class="grid-item">Header</header>
<section class="grid-item">Section</section>
<section class="grid-item">Section</section>
<aside class="grid-item">Aside</aside>
<footer class="grid-item">Footer</footer>
</div>
grid-template-rows
와 grid-template-columns
는 모두 Grid Track의 크기를 정의grid-template-rows
로 지정grid-template-columns
로 지정grid-template
적용 예시.main {
display: grid;
grid-template-rows: 40px 40px 40px;
grid-template-columns: 40px 80px 40px;
}
grid-template-rows: 40px 40px 40px;
와 같이 반복되는 값을 쉽게 할당하는 법 ⇒ repeat()
함수를 사용repeat()
함수는 grid-template-columns
와 grid-template-rows
에서만 사용할 수 있다는 점 참고/* 2, 3번째 라인은 동일한 뜻을 지님 */
grid-template-columns: 40px repeate(4, 80px) 40px;
grid-template-columns: 40px 80px 80px 80px 80px 40px;
/* 6, 7번째 라인은 동일한 뜻을 지님 */
grid-template-columns: repeate(4, 40px 80px);
grid-template-columns: 40px 80px 40px 80px 40px 80px 40px 80px;
fr
은 fraction의 약자로 파편, 분수라는 뜻fr
은 Grid Container에 남은 공간의 비율을 나타내는 유연한 단위500px
이라면 grid-template-columns: 1fr 3fr 1fr;
로 설정했을 때 Grid Track을 1 : 3 : 1의 비율로 나누니 각각 100px, 300px, 100px
을 차지 fr
은 비율이기 때문에 Grid Container의 너비가 변하더라도 해당 비율을 유지grid-template-areas
를 이용하여 Grid Area의 이름을 할당 .main {
display: grid;
grid-template-rows: 128px auto 240px;
grid-template-columns: 1fr 3fr 1fr;
grid-template-areas:
"hd hd hd"
"nav content ad"
"ft ft ft";
}
header,nav,section,aside,footer {
border: 4px solid;
padding: 8px;
margin: 2px;
text-align: center;
}
header {
grid-area: hd;
border-color: purple;
}
nav {
grid-area: nav;
border-color: blue;
}
section {
grid-area: content;
border-color: yellow;
}
aside {
grid-area: ad;
border-color: red;
}
footer {
grid-area: ft;
border-color: green;
}
grid-template-areas
가 적용되는 방식을 엑셀로 보기grid-template-areas
의 영역을 할당하는 방법은 간단. Grid Area에 붙인 이름을 원하는 칸에 배치 grid-template-areas
의 값은 ""
로 한 행을 표현하며, 여러 행을 띄어쓰기로 구분grid-template-areas: "1행 1행 1행" "2행 2행 2행" "3행 3행 3행"
/* 둘 다 가능 🟢 */
grid-template-areas:
"1행 1행 1행"
"2행 2행 2행"
"3행 3행 3행"
grid-template-areas: /* ㄴ 모양 ❌ */
"hd hd hd"
"nav content ad"
"nav nav ft";
grid-template-areas: /* ㅗ 모양 ❌ */
"hd hd hd"
"nav ft ad"
"ft ft ft";
grid-template-areas
의 값은 Grid 전체를 나타내야 하는 점을 주의. 전체 Grid Area 수와 동일grid-template
는 grid-template-xxx
에 해당하는 모든 프로퍼티의 단축 프로퍼티.main {
display: grid;
grid-template:
"hd hd hd" 128px
"nav content ad" auto
"ft ft ft" 240px
/ 1fr 3fr 1fr;
}
.main {
display: grid;
grid-template-rows: 128px auto 240px;
grid-template-columns: 1fr 3fr 1fr;
grid-template-areas:
"hd hd hd"
"nav content ad"
"ft ft ft";
}
.main {
display: grid;
grid-template: 128px auto 240px / 1fr 3fr 1fr
}
.main {
display: grid;
grid-template-rows: 128px auto 240px;
grid-template-columns: 1fr 3fr 1fr;
}
grid-row-gap
과 grid-column-gap
을 통해 각 행과 열 사이의 간격을 지정.main {
display: grid;
grid-template:
"hd hd hd" 128px
"nav content ad" auto
"ft ft ft" 240px
/ 1fr 3fr 1fr;
grid-row-gap: 16px;
grid-column-gap: 16px;
}
header,nav,section,aside,footer {
border: 4px solid;
padding: 8px;
text-align: center;
}
header {
grid-area: hd;
border-color: purple;
}
nav {
grid-area: nav;
border-color: blue;
}
section {
grid-area: content;
border-color: yellow;
}
aside {
grid-area: ad;
border-color: red;
}
footer {
grid-area: ft;
border-color: green;
}
grid-gap
은 grid-row-gap
과 grid-column-gap
의 단축 프로퍼티grid-row-gap
을 처음 값으로, grid-column-gap
을 두번째 값으로 사용grid-row-gap
과 grid-column-gap
모두 동일한 값으로 지정grid-row-gap: 16px;
grid-column-gap: 16px;
/* 위와 아래의 코드는 동일합니다. */
grid-gap: 16px 16px;
/* 모두 동일한 코드입니다. */
grid-gap: 16px;
grid-auto-rows
와 grid-auto-columns
는 크기가 지정되지 않은 Grid Track의 크기를 지정할 수 있는 프로퍼티<article class="photos">
<div class="card">1</div>
<div class="card">2</div>
<div class="card">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</div>
<div class="card">4</div>
<div class="card">5</div>
</article>
body {
background-color: #eee;
}
.photos {
display: grid;
grid-gap: 8px;
grid-template-columns: repeat(3, 1fr);
}
.card {
background: #fff;
box-shadow: 0px 2px 8px rgba(0,0,0, .2);
border-radius: 8px;
padding: 24px;
}
.photos {
display: grid;
grid-gap: 8px;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 200px);
}
minmax(최솟값, 최댓값)
함수는 첫 번째 매개변수로 최솟값을, 두 번째 매개변수로 최댓값으로 받습니다. 함수를 아래와 같이 사용하면 행의 크기는 최소 200px
으로, 최대는 auto
로 설정되어 내용에 따라 자동으로 크기가 늘어난다.photos {
display: grid;
grid-gap: 8px;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, minmax(200px, auto));
}
<article class="photos">
<div class="card">1</div>
<div class="card">2</div>
<div class="card">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</div>
<div class="card">4</div>
<div class="card">5</div>
<div class="card">6</div>
<div class="card">7</div>
<div class="card">8</div>
<div class="card">9</div>
<div class="card">10</div>
<div class="card">11</div>
<div class="card">12</div>
<div class="card">13</div>
<div class="card">14</div>
</article>
.photos {
display: grid;
grid-gap: 8px;
grid-template-columns: repeat(3, 1fr);
grid-auto-rows: minmax(200px, auto);
}
grid-auto-flow
는 Grid가 자동으로 배치되는 방향을 결정.card
가 Grid Container 내부에 배치<article class="photos">
<div class="card">1</div>
<div class="card">2</div>
</article>
body {
background-color: #eee;
}
.photos {
display: grid;
grid-gap: 8px;
grid-template-columns: repeat(2, 100px);
}
.card {
background-color: #fff;
box-shadow: 0px 2px 8px rgba(0,0,0, .2);
border-radius: 8px;
padding: 24px;
}
<article class="photos">
<div class="card">1</div>
<div class="card">2</div>
<div class="card">3</div>
</article>
.photos {
display: grid;
grid-gap: 8px;
grid-template-columns: repeat(2, 100px);
grid-auto-flow: column;
}
grid-auto-flow
는 row, column, row dense, column dense를 값으로 가질 수 있다.body {
background-color: #eee;
}
.photos {
display: grid;
grid-gap: 8px;
grid-template-columns: repeat(2, 100px);
grid-auto-flow: row;
}
.card {
background-color: #fff;
box-shadow: 0px 2px 8px rgba(0,0,0, .2);
border-radius: 8px;
padding: 24px;
}
.card:nth-child(1) {
grid-column-start: 2; /* Grid Item 관련 프로퍼티에서 자세히 알려드리겠습니다. */
}
.photos {
display: grid;
grid-gap: 8px;
grid-template-columns: repeat(2, 100px);
grid-auto-flow: row dense;
}
body {
background-color: #eee;
}
.photos {
display: grid;
grid-gap: 8px;
/*grid-template-columns: repeat(2, 100px);*/
grid-template-columns: repeat(4, 100px);
grid-auto-flow: row;
}
.card {
background-color: #fff;
box-shadow: 0px 2px 8px rgba(0,0,0, .2);
border-radius: 8px;
padding: 24px;
}
.card:nth-child(1) {
/* grid-column-start: 2; */
grid-column-start: 4;
}
grid
는 grid-template
와 grid-auto
의 단축형 프로퍼티grid
는세 가지 형태의 값을 가질 수 있다.grid: <grid-template>;
grid: <grid-template-rows> / auto-flow <grid-auto-columns>;
grid: auto-flow <grid-auto-rows> / <grid-template-columns>;
grid
는 gird-template
로 쓸 수 있다..main {
display: grid;
grid:
"hd hd hd" 128px
"nav content ad" auto
"ft ft ft" 240px
/ 1fr 3fr 1fr;
}
.main {
display: grid;
grid-template:
"hd hd hd" 128px
"nav content ad" auto
"ft ft ft" 240px
/ 1fr 3fr 1fr;
}
.main {
display: grid;
grid: 128px auto 240px / 1fr 3fr 1fr;
grid-template-areas:
"hd hd hd"
"nav content ad"
"ft ft ft";
}
.main {
display: grid;
grid-template: 128px auto 240px / 1fr 3fr 1fr;
grid-template-areas:
"hd hd hd"
"nav content ad"
"ft ft ft";
}
grid
로 grid-template-rows
와 grid-auto
를 동시에 적용
.photos {
display: grid;
grid-gap: 8px;
grid: auto-flow 100px / repeat(2, 100px);
}
.photos {
display: grid;
grid-gap: 8px;
grid-template-columns: repeat(2, 100px);
grid-auto-rows: 100px;
grid-auto-flow: row;
}
.photos {
display: grid;
grid-gap: 8px;
grid: auto-flow dense 100px / repeat(2, 100px);
}
.photos {
display: grid;
grid-gap: 8px;
grid-template-columns: repeat(2, 100px);
grid-auto-rows: 100px;
grid-auto-flow: row dense;
}
/
뒤에 사용하기 때문에 이 형식을 쓰는 방법은 grid-auto-flow: column
의 값을 가짐.photos {
display: grid;
grid-gap: 8px;
grid: repeat(2, 100px) / auto-flow 100px;
/* grid: repeat(2,100px) / auto-flow dense; */
}
.photos {
display: grid;
grid-gap: 8px;
grid-template-rows: repeat(2, 100px);
grid-auto-columns: 100px;
grid-auto-flow: column;
/* grid-auto-flow: column dense; */
}
align
은 수직 방향 정렬을, justify
는 수평 방향 정렬place
는 align
과 justify
의 축약형 content
는 Grid Container를 기준으로 Grid Cell을 정렬items
는 Grid Cell 혹은 Grid Area를 기준으로 Grid Item을 정렬 -
앞부분인 align
와 justify
에 영향을 받지 않고, 오로지 content
와 items
에만 영향을 받는 값 제목 없음content
에 해당하는 값들을 실제로 사용하면 다음과 같다 align-content: center;
는 Grid Container 기준 수직 방향으로 Grid Cell들을 중앙 정렬 place-xxx
는 xxx-content
와 xxx-items
의 축약 프로퍼티align
을 먼저 쓰고 그 다음 justify
가 따라온다place-content: <align-content> <justify-content>;
place-items: <align-items> <justify-items>;
.container {
place-content: space-around space-evenly;
place-items: center stretch;
}
.container {
align-content: space-around;
justify-content: space-evenly;
align-items: center;
justify-items: stretch;
}
.container {
place-content: stretch;
place-items: end;
}
.container {
align-content: stretch;
justify-content: stretch;
align-items: end;
justify-items: end;
}
grid-row
와 grid-column
을 통해 Grid Item의 행, 열의 시작 위치와 끝 위치를 지정 grid-row
와 grid-column
의 값으로 주어 Grid Item이 배치될 위치를 지정할 수 있다.grid-row
는 grid-row-start
와 grid-row-end
의 축약형grid-row-start
는 해당 Grid Item의 행 방향으로의 시작 위치를 지정grid-row-end
는 이와 반대로 끝나는 위치를 지정grid-row: <grid-row-start> / <grid-row-end>
grid-column: <grid-column-start> / <grid-column-end>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
</div>
.item:nth-child(1) {
grid-column: 1 / 3;
}
.item:nth-child(1) {
grid-column: 1 / 3;
}
.item:nth-child(2) {
grid-row: 1 / 3;
}
.item:nth-child(1) {
grid-column: 1 / 3;
grid-row: 1;
}
.item:nth-child(2) {
grid-row: 1 / 3;
}
.item:nth-child(1) {
grid-column: 1 / 3;
}
.item:nth-child(2) {
grid-row: 1 / 3;
grid-column: -2;
}
.item:nth-child(3) {
grid-row: 2 / 4;
}
.item:nth-child(3) {
grid-row: 2 / span 2;
}
.item:nth-child(3) {
grid-row: span 2 / 4;
}
grid-area
는 grid-row
와 grid-column
의 단축 속성 역할auto
의 값을 가진다grid-area: <Grid Area 이름>
grid-area: <grid-row-start> / <grid-column-start> / <grid-row-end> / <grid-column-end>;
xxx-self
는 해당 Grid Item을 정렬하는데 사용align-self
는 수직 정렬jusify-self
는 수평 정렬 align-self
, jusify-self
모두 start, center, end, stretch 값을 가질 수 있다.<h1>Hello Goorm</h1><div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
</div>
.container {
width: 400px;
height: 400px;
background: skyblue;
padding: 16px;
display: grid;
grid-template: repeat(2, 1fr) / repeat(2, 1fr);
grid-gap: 16px;
}
.item {
border: 2px dashed red;
background: #fff;
text-align: center;
width: 100px;
height: 100px;
font-size: 1.5rem;
}
.item:nth-child(1) {
align-self: start;
}
.item:nth-child(2) {
align-self: center;
}
.item:nth-child(3) {
align-self: end;
}
.item:nth-child(4) {
align-self: stretch;
}
justify-self
도 방향만 다를 뿐 동일하게 동작 place-self
는 align-self
와 jusify-self
의 단축 프로퍼티place-self: <align-self> <justify-self>;
align-self: end;
jusify-self: center;
place-self: end center;
inherit
을 주어 해결할 수 있다.<div class="main">
main
<div class="sub">
inner
</div>
</div>
.main {
background-color: skyblue;
width: 100px;
padding: 24px;
}
.sub {
background-color: pink;
}
.sub
도 .main
과 같이 padding
을 24px
을 주고 싶으면 아래와 같이 작성하여 값을 쉽게 줄 수 있다..sub {
background-color: pink;
padding: inherit;
}
<head>
태그 내의 <style>
태그<head>
태그 내의 <style>
태그 내의 @import
문<link>
태그로 연결된 CSS<link>
태그로 연결된 CSS 내의 @import
문!important
inherit
transition-delay
에서 delay
는 '지연'을 뜻합니다.transition
이 발생할 때 얼만큼 기다렸다가 실행할지 결정해주는 속성
단위인 s
나 밀리 초 단위인 ms
로 나타냅니다.
0s
가 입력되어 바로 transition
이 발생프로퍼티 값은 음수 값 지정이 가능
- 지정한 음수 값의 절대값 시간만큼 건너뛰고 시작
duration
은 '지속'이라는 뜻을 가진 프로퍼티transition
이 발생하는 지속 시간을 지정
transition-duration
을 지정하면 좀 더 애니매이션 같은 효과를 표현
delay
와 같이 시간을 속성 값으로 가지며, 초 단위를 나타내는 s
나 밀리 초를 나타내는 ms
로 나타냅니다.
- 프로퍼티 값을 지정해주지 않으면 자동으로 0s
가 입력되어 transition
의 효과가 나타나지 않습니다.
transition-property
는 프로퍼티를 위한 프로퍼티transition-property
의 속성 값에 따라 transition
효과를 지정할 프로퍼티가 정해집니다.property
의 기본 값으로, 모든 속성에 transition
효과가 적용 width
를 지정한 경우transition-timing-function
은 transition
의 진행 속도를 설정하는 프로퍼티transition-timing-function
은 IE의 경우 버전 10부터 사용 가능한 점 참고)박스에 마우스를 올려 보세요.
<div class="ease">ease</div>
<div class="linear">linear</div>
<div class="ease-in">ease-in</div>
<div class="ease-out">ease-out</div>
<div class="ease-in-out">ease-in-out</div>
<div class="step-start">step-start</div>
<div class="step-end">step-end</div>
.ease:hover {
transition-timing-function: ease;
}
.linear:hover {
transition-timing-function: linear;
}
.ease-in:hover {
transition-timing-function: ease-in;
}
.ease-out:hover {
transition-timing-function: ease-out;
}
.ease-in-out:hover {
transition-timing-function: ease-in-out;
}
.step-start:hover {
transition-timing-function: step-start;
}
.step-end:hover {
transition-timing-function: step-end;
}
transition : width 2s linear 1s;
/* 위와 아래는 동일한 코드 입니다. */
transition-property: width;
transition-duration: 2s;
transition-timing-function: linear;
transition-delay: 1s;
<div class="box">transition</div>
.box {
transition : width 2s linear 1s;
}
scale
은 형태의 크기를 변환시킬 때 사용하는 프로퍼티width
와 height
의 크기가 중심점을 기준으로 늘어나는 것을 볼 수 있습니다. width
와 height
를 늘리는 효과는 오른쪽 아래 방향으로 진행되나, scale
을 사용하면 변형 중심점이 가운데로 지정되기 때문에 가운데를 중심으로 커지는 효과를 볼 수 있습니다.scale(1)
에서 1은 100%를 뜻하기 때문에 1 이상의 값을 입력해야 변하는 모습을 확인scale
의 괄호 안에는 2가지 인자를 넣을 수 있습니다. 인자는 각각 x축, y축을 의미.box:hover{
transform:scale(3, 2);
}
rotate
는 직역하면 '회전하다'는 뜻이며, 말 그대로 객체를 회전.box:hover{
transform: rotate(360deg);
}
360deg
는 한 바퀴를 뜻하는데 transform:rotate(1turn)
으로 또한 작성 translate
는 객체를 (x, y) 지점으로 옮기고 싶을 때 사용scale
과 동일하게 가운데이며, 각 값이 증가할 때 x축 기준 오른쪽 방향으로, y축 기준 아래 방향으로 이동.box:hover{
transform: translate(100px, 100px);
}
.box:hover{
transform: translate(-100px);
}
scale
과 달리 x축 방향으로만 변하는 것을 확인skew
는 '왜곡하다'라는 단어로, 객체를 비틀거나 그 기본 형태를 왜곡하고 싶을 때 사용rotate
와 같은 각도 값이며 단위 또한 deg(dgree)로 동일transform: skew(x축, y축);
transform
의 속성 값은 대문자 X
와 Y
를 붙여 따로 지정할 수 있습니다.transform: scaleX(2);
transform: translateY(100px);
transform: rotateX(240deg);
skew
에서 설정한 방향으로 설정한 각도만큼 당기는 모양skewX
를 20deg로 설정, skewX
를 사용하면 X축을 기준으로 비튼다.box:hover{
transform: skewX(20deg);
}
.box:hover{
transform: skewY(20deg);
}
.box:hover{
transform: skew(20deg, 20deg);
}
transform-origin
을 사용하면 기준점을 원하는 위치로 설정rotate
되는 위치가 왼쪽 위부터 시작하도록 변경 transition
속성과 animation
속성은 Javascript의 도움 없이 대상에 직접 애니메이션 효과를 적용할 때 사용transition
은 요소의 상태가 변경되어야 애니메이션을 실행animation
속성은 요소의 상태 변화와 상관 없이 애니메이션을 실행animation
속성은 transition
과 달리 @keyframes
속성을 이용해 프레임을 추가transition
의 움직임에 원하는 컨트롤을 추가하여 좀 더 역동적으로 변경 @keyframes
은 애니메이션이 만들어지는 부분을 뜻합니다.from
속성이나 0%
속성에 설정한 스타일부터 to
속성이나 100%
속성에 설정한 스타일로 점차 변경하며 애니메이션이 재생/* [ from ~ to 속성 ] **/
@keyframes animation-name {
/** 애니메이션의 시작 프레임 **/
from {
styles;
}
/** 애니메이션의 종료 프레임 */
to {
styles;
}
/* [ 0% ~ 100% 속성 ] **/
@keyframes animation-name {
/** 애니메이션의 시작 프레임 **/
0% {
styles;
}
50% {
styles;
}
/** 애니메이션의 종료 프레임 */
100% {
styles;
}
@keyframes
은 CSS 스타일의 변화 과정을 나타낼 때 사용@keyframes
을 이용한 애니메이션은 transition
보다 더 정밀한 효과를 구현name
은 @keyframes
속성에서 설정한 이름을 동일하게 사용/* 키프레임 이름 == 애니메이션 이름 */
@keyframes goorm {
0% {
styles;
}
100% {
styles;
}
}
div{
/* 애니메이션 이름 */
animation-name: goorm;
}
animation-name
은 다음과 같이 정해진 규칙에 따라 그 이름을 작성animation-name
을 시작할 땐 영문 소문자, 문자열, 언더바(_), 하이픈(-)을 사용해야 합니다.
영문 대문자, 숫자, 특수문자는 사용할 수 없습니다. (단, 파일 및 폴더 명에는 허용)
여러 개의 animation-name
을 동시에 나열해야 할 경우 ','를 사용합니다.
/* [ 올바른 이름 예시 ] */
animation-name: goorm; /* 영문 소문자로 시작하는 이름 */
animtaion-name: -goorm; /* 언더바(_)로 시작하는 이름 */
animation-name: -goorm; /* 하이픈(-)으로 시작하는 이름 */
animation-name: goorm1, goorm2; /* 여러 개의 animation-name 나열 */
/* [ 잘못된 이름 예시 ] */
animation-name: Goorm-edu; /* 영문 대문자로 시작하는 이름 */
animation-name: *-goorm-ide; /* 특수문자로 시작하는 이름 */
animation-name: 1goorm; /* 숫자로 시작하는 이름 */
duration
속성은 애니메이션의 시작부터 종료까지의 총 지속 시간을 설정할 때 사용duration
값은 양수로 지정해야 그 결과를 확인/* [ 애니메이션이 재생되지 않는 경우 ] */
animation-duration: 0; /* 재생시간이 0인 경우 */
animation-duration: -3s; /* 재생시간이 음수인 경우 */
/* [ 애니메이션이 재생되는 경우 ] */
animation-duration: 3s; /* 재생시간이 양수인 경우 */
animation-duration: 500ms; /* 1초 이하의 재생시간을 입력할 경우 */
/* [ 애니메이션이 재생되지 않는 경우 ] */
animation-iteration-count: 0; /* 재생횟수가 0인 경우 */
animation-iteration-count: -3; /* 재생횟수가 음수인 경우 */
/* [ 애니메이션이 재생되는 경우 ] */
animation-iteration-count: 3; /* 재생횟수가 양수인 경우 */
animation-iteration-count: 1.5; /* 재생횟수가 실수인 경우 */
animation-iteration-count: infinite; /* 애니메이션을 무한 반복할 경우 */
iteration-count
속성은 애니메이션을 재생하는 횟수를 지정할 때 사용iteration-count
속성의 기본 값은 1입니다.
값을 0으로 지정하면 애니메이션이 재생되지 않습니다.
속성 값을 음수로 지정하면 기본 값인 1과 같은 결과를 출력합니다.
1.5와 같은 양의 유리수로 속성 값을 지정하면 애니메이션 재생 도중 첫 번째 프레임으로 돌아가 종료됩니다.
infinite
로 값을 설정할 경우 애니메이션을 무한 반복할 수 있습니다.
/* [ 애니메이션이 재생되지 않는 경우 ] */
animation-iteration-count: 0; /* 재생횟수가 0인 경우 */
animation-iteration-count: -3; /* 재생횟수가 음수인 경우 */
/* [ 애니메이션이 재생되는 경우 ] */
animation-iteration-count: 3; /* 재생횟수가 양수인 경우 */
animation-iteration-count: 1.5; /* 재생횟수가 실수인 경우 */
animation-iteration-count: infinite; /* 애니메이션을 무한 반복할 경우 */
timing-function
은 애니메이션 @keyframes
사이의 재생 속도를 조절하는 속성timing-function
속성으로는 ease
, linear, ease-in, ease-out, ease-in-out, cubic-bezier(n, n, n, n)
등이 있습니다.[ 같은 애니메이션 결과를 출력하는 속성값 ]
animation-timing-function: ease; /* 기본값 */
animation-timing-function: cubic-bezier(0,25, 0.1, 0.25, 1);
animation-timing-function: linear;
animation-timing-function: cubic-bezier(0,0,1,1);
animation-timing-function: ease-in;
animation-timing-function: cubic-bezier(0.42,0,1,1);
animation-timing-function: ease-out;
animation-timing-function: cubic-bezier(0,0,0.58,1);
animation-timing-function: ease-in-out;
animation-timing-function: cubic-bezier(0.42,0,0.58,1);
direction
속성을 사용direction
속성의 기본 값은 normal
normal
은 from
에 설정된 스타일에서 to
에 설정된 스타일대로 재생하거나, 0%
에 설정된 스타일에서 100%
에 설정된 스타일대로 재생animation-direction: normal; /* 순방향 재생 */
animation-direction: reverse; /* 역방향 재생 */
animation-direction: alternate; /* 순방향 시작, 순방향-역방향 번갈아 재생 */
animation-direction: alternate-reverse; /* 역방향 시작, 역방향-순방향 번갈아 재생 */
alternate
은 순방향으로 애니메이션을 시작해 실행 횟수가 홀수일 때에는 순방향, 짝수일 때에는 역방향으로 재생alternate-reverse
은 역방향으로 애니메이션을 시작해 실행 횟수가 홀수일 때에는 역방향, 짝수 일 때에는 순방향으로 재생 animation-delay: 0; /* 바로 재생 */
animation-delay: now; /* 바로 재생 */
animation-delay: 1.5s; /* 지연 재생 */
animation-delay: -500ms; /* 지정 시간 이후 프레임부터 바로 재생 */
play-state
는 재생여부를 설정할 때 사용running
일 경우 애니메이션을 재생하고, paused
일 경우 애니메이션을 정지