๐โโ๏ธ CSS๋,
Cascading Style Sheets์ ์ฝ์์ด๋ฉฐ, ๋ฌธ์ฅ์ ๋์์ธ์ ์ ํ ๋ ์ฌ์ฉํ๋ ์ธ์ด
๐โโ๏ธ ์ ํ์(selector)๋,
ํน์ ํ HTML ํ๊ทธ๋ฅผ ์ ํํ ๋ ์ฌ์ฉํ๋ ๊ธฐ๋ฅ์ผ๋ก, ํ๊ทธ๋ฅผ ์ ํํ์ฌ ์ํ๋ ์คํ์ผ๊ณผ ๊ธฐ๋ฅ์ ์ ์ฉ
{}
: HTML ๋ฌธ์ ์์ ๋ชจ๋ ํ๊ทธ๋ฅผ ์ ํํ ๋ ์ฌ์ฉ
{ color : red;}
/* ๋ชจ๋ ํ
์คํธ๊ฐ red๋ก ๋ณ๊ฒฝ */
p {}
: HTML ๋ฌธ์ ๋ด์ ๊ฐ์ ํ๊ทธ๋ฅผ ๋ชจ๋ ์ ํํ ๋ ์ฌ์ฉ
p { color : gray; }
#ID {}
: HTML ๋ฌธ์ ๋ด์ ํด๋นํ๋ ์์ด๋ ์์ฑ์ ๊ฐ์ง ํ๊ทธ๋ง ์ ํํ ๋ ์ฌ์ฉ
#id2, #id4 {
background-color : lightcoral; /* ๋ฐฐ๊ฒฝ์ */
color : white; /* ๊ธ์จ์ */
}
<ol>
<li id="id1">์์ด๋ ์ ํ์ ํ
์คํธ</li>
<li id="id2">์์ด๋ ์ ํ์ ํ
์คํธ</li>
<li id="id3">์์ด๋ ์ ํ์ ํ
์คํธ</li>
<li id="id4">์์ด๋ ์ ํ์ ํ
์คํธ</li>
<li id="id5">์์ด๋ ์ ํ์ ํ
์คํธ</li>
</ol>
<!-- ์๋ฐ์คํฌ๋ฆฝํธ์ ํจ๊ป ์ฌ์ฉ์, ํน์ ํ ID(๊ณ ์ ๊ฐ)๋ฅผ ๊ฐ์ง ์๋ฆฌ๋จผํธ๋ฅผ ๋์์ํค๊ณ ์ถ์ ๋ ๋ง์ด ์ฌ์ฉ-->
.class {}
: HTML ๋ฌธ์ ๋ด์ ์ฌ๋ฌ ๊ฐ์ ํ๊ทธ๋ฅผ ๋์ผํ ํด๋์ค๋ช
์ผ๋ก ์ง์ ํ์ฌ ์ ํํ ๋ ์ฌ์ฉ
.class1 {
background-color: lightgreen;
color : red;
}
<ul>
<li class="class1">ํด๋์ค ์ ํ์ ํ
์คํธ</li>
<li class="class2">ํด๋์ค ์ ํ์ ํ
์คํธ</li>
<li class="class1">ํด๋์ค ์ ํ์ ํ
์คํธ</li>
<li class="class2">ํด๋์ค ์ ํ์ ํ
์คํธ</li>
<li class="class1">ํด๋์ค ์ ํ์ ํ
์คํธ</li>
</ul>
์ ํ์[์์ฑ=ํน์ ๊ฐ] { ์ค์ ๋ด์ฉ }
=
: ์์ฑ ๊ฐ์ด ํน์ ๊ฐ์ธ ํ๊ทธ ์ ํ
~=
: ์์ฑ ๊ฐ์ด ํน์ ๊ฐ์ ํฌํจํ๋ ํ๊ทธ ์ ํ(๋์ด์ฐ๊ธฐ ๊ตฌ๋ถ)
|=
: ์์ฑ ๊ฐ์ด ํน์ ๊ฐ์ ๋จ์ด๋ก ํฌํจํ๋ ํ๊ทธ ์ ํ (-์ผ๋ก ๊ตฌ๋ถํ๋ฉฐ - ์์ ๋ด์ฉ์ด ๊ฐ๊ณผ ๋์ผํด์ผํจ)
^=
: ์์ฑ ๊ฐ์ด ํน์ ๊ฐ์ผ๋ก ์์ํ๋ ํ๊ทธ ์ ํ
$=
: ์์ฑ ๊ฐ์ด ํน์ ๊ฐ์ผ๋ก ๋๋๋ ํ๊ทธ ์ ํ
*=
: ์์ฑ ๊ฐ์ด ํน์ ๊ฐ์ ํฌํจํ๋ ํ๊ทธ ์ ํ (ํด๋น ๊ฐ์ด ์ ์ด๋ ํ๋ ์กด์ฌํ๋ค๋ ๊ฐ์ ํ์)
div[name=name2] { background: skyblue; }
/* ๋ค๋ฅธ name์ name1์ด ํฌํจ๋์ด์์ผ๋ฉด ๊ทธ๊ฒ ๋ํ ์ ์ฉ ๋์ */
div[name~=name1] { background: pink;}
/* class์์ -์์ด class์ธ name4์๋ง ์ ์ฉ */
div[class|=class] {background: cyan;}
/* name์ด name์ผ๋ก ์์ํ๋ ๋ชจ๋ ๊ฒ์ ์ ์ฉ */
div[name^=name] {background: gray;}
/* class๊ฐ class๋ก ๋๋๋ ๊ฒ์ ์ ์ฉ */
div[class$=class] {color: white;}
/* class์ div๊ฐ ํฌํจํ๋ ๋ชจ๋ ๊ฒ์ ์ ์ฉ */
div[class*=div] {background: salmon;}
<div name="name1" class="div-class">div 1</div>
<div name="name2" class="div-class">div 2</div>
<div name="name3 name1" class="div-class">div 3</div>
<div name="name4" class="class-div">div 4</div>
์ ํ์>์์์ ํ์ { ์ค์ ๋ด์ฉ }
: ์์์ ํ์
์ ํ์ ํ์์ ํ์ { ์ค์ ๋ด์ฉ }
: ํ์์ ํ์
/* div test1์ ์์ h4 */
#test1>h4 {
background: pink;
}
/* div test1์ ์์ ul์ ์์ li */
#test1>ul>li {
background: skyblue;
}
* div test1์ ํ์ li */
/* ๋ฐ๋ก ์์ ๊ฐ์ ์๋ฏธ์ด์ง๋ง ๋์ด์ฐ๊ธฐ๋ก ๊ฐ๊ฒฐํ๊ฒ ํ์ ํํ ๊ฐ๋ฅ */
#test1 li {
color : white
}
<div id="test1">
<h4>div test1์ ์์์
๋๋ค.</h4>
<h4>๋๋ div test1์ ์์์
๋๋ค.</h4>
<ul id="testul">
<li>๋๋ ul์ ์์์ด๋ฉด์ ๋์์ div์ ํ์์
๋๋ค.</li>
<li>๋๋ ul์ ์์์ด๋ฉด์ ๋์์ div์ ํ์์
๋๋ค.</li>
</ul>
</div>
์ ํ์ + ์ ํ์ { ์ค์ ๋ด์ฉ }
: ๋ฐ๋ก ๋ค์ ์๋ ์์ ์ ํ
์ ํ์ ~ ์ ํ์ { ์ค์ ๋ด์ฉ }
: ๋ค์ ์๋ ๋ชจ๋ ์์ ์ ํ
/* ์ ํ์ ๋ฐ๋ก ๋ค์ ์์ ์ ํ ์ */
#div-test1 + div { background: yellow; }
/* ์ ํ์ ๋ค์ ๋ชจ๋ ์์ ์ ํ์ */
#div-test2 ~ div { background: orangered; }
<div>
<div id="div-test1">div test1</div>
<div id="div-test2">div test2</div>
<div id="div-test3">div test3</div>
<div id="div-test4">div test4</div>
<div id="div-test5">div test5</div>
</div>
์ ํ์:active { ์ค์ ๋ด์ฉ }
: ์ฌ์ฉ์๊ฐ ํด๋ฆญํ ํ๊ทธ
์ ํ์:hover { ์ค์ ๋ด์ฉ }
: ์ฌ์ฉ์์ ๋ง์ฐ์ค๊ฐ ์ฌ๋ผ๊ฐ ํ๊ทธ
/* div ์์ญ ํ์๋ฅผ ์ํ ์คํ์ผ ์ ์ฉ */
#active-test,
#hover-test {
width: 300px;
height: 300px;
background-color: bisque; /* ๊ธฐ๋ณธ์ผ๋ก ๋ณด์ฌ์ง๋ ์ */
color: white;
}
/* ํด๋ฆญํ ํ๊ทธ ์ ํ์*/
#active-test:active {
background-color: aquamarine; /* ํด๋ฆญ ํ์ ๋ ์ด ์์ผ๋ก ๋ณ๊ฒฝ */
}
/* ๋ง์ฐ์ค ์ค๋ฒํ ํ๊ทธ ์ ํ์ */
#hover-test:hover {
background: pink; /* ๋ง์ฐ์ค ์ค๋ฒ ํ์ ๋ ์ด ์์ผ๋ก ๋ณ๊ฒฝ */
cursor: pointer; /* ํด๋ฆญํ ์ ์๋ ์ปค์๋ก ๋ณ๊ฒฝ */
}
<div id="active-test">active ํ
์คํธ</div>
<br>
<div id="hover-test">hover ํ
์คํธ</div>
inputํ๊ทธ:checked { ์ค์ ๋ด์ฉ }
: ์ฒดํฌ ์ํ์ input ํ๊ทธ ์ ํ
inputํ๊ทธ:focus { ์ค์ ๋ด์ฉ }
: ์ด์ ์ด ๋ง์ถ์ด์ง input ํ๊ทธ ์ ํ
inputํ๊ทธ:enabled { ์ค์ ๋ด์ฉ }
: ์ฌ์ฉ ๊ฐ๋ฅํ input ํ๊ทธ ์ ํ
inputํ๊ทธ:disabled { ์ค์ ๋ด์ฉ }
: ์ฌ์ฉ ๋ถ๊ฐ๋ฅํ input ํ๊ทธ ์ ํ
/* ์ฒดํฌ ๋ฐ์ค๊ฐ ์ฒดํฌ ๋ ๊ฒฝ์ฐ */
input[type=checkbox]:checked { /* : type์ด checkbox์ธ ๊ฒ๋ค ์ค check๋ ๊ฒ */
width: 30px;
height: 30px;
}
/* ์ด์ ์ด ๋ง์ถ์ด์ง input ํ๊ทธ ์ ํ */
#userid:focus,
#userpwd:focus {
background: lightgray; /* ์
๋ ฅ ์๋ ์, input ๋ฐ์ค์ ์์ด ์ด ์์ผ๋ก ๋ณ๊ฒฝ */
}
/* ์ฌ์ฉ ๋ถ๊ฐ๋ฅํ ์ต์
*/
option:disabled {background: gray;}
/* ์ฌ์ฉ ๊ฐ๋ฅํ ์ต์
*/
option:enabled {background: yellowgreen;}
<input type="checkbox" id="apple" name="fruits" value="apple">
<label for="apple">์ฌ๊ณผ</label>
<input type="checkbox" id="banana" name="fruits" value="banana">
<label for="banana">๋ฐ๋๋</label>
<input type="checkbox" id="peach" name="fruits" value="peach">
<label for="peach">๋ณต์ญ์</label>
<label for="userid">์์ด๋ : </label>
<input type="text" id="userid" placeholder="์์ด๋ ์
๋ ฅ">
<label for="userpwd">๋น๋ฐ๋ฒํธ : </label>
<input type="password" id="userpwd" placeholder="๋น๋ฐ๋ฒํธ ์
๋ ฅ">
<h3>๋น์ ์ ์ฐ๋ น๋๋?</h3>
<select>
<!-- disabled : ์
๋ ฅ/์ ํ ๋ถ๊ฐ ์ํ๋ก ์ค์ -->
<option disabled>10๋</option>
<option>20๋</option>
<option>30๋</option>
<option>40๋</option>
<option>50๋</option>
<option disabled>60๋</option>
</select>
'์์น'๋ก ๊ตฌ๋ถ
์ ํ์:first-child { ์ค์ ๋ด์ฉ }
: ํ์ ๊ด๊ณ ํ๊ทธ ์ค ์ฒซ ๋ฒ์ฌ ํ๊ทธ ์ ํ
์ ํ์:last-child { ์ค์ ๋ด์ฉ }
: ํ์ ๊ด๊ณ ํ๊ทธ ์ค ๋ง์ง๋ง ํ๊ทธ ์ ํ
์ ํ์:nth-child(xn) { ์ค์ ๋ด์ฉ }
: ํ์ ๊ด๊ณ ํ๊ทธ ์ค ์์์ x์ ๋ฐฐ์ ํ๊ทธ ์ ํ
์ ํ์:nth-last-child(x) { ์ค์ ๋ด์ฉ }
: ํ์ ๊ด๊ณ ํ๊ทธ ์ค ๋ค์์ x๋ฒ์งธ ํ๊ทธ ์ ํ
/* : test1์ ์์์ธ p์ค ์ฒซ ๋ฒ์งธ ์์*/
#test1 p:first-child {
background: palegoldenrod;
color: white;
}
/* ๋ง์ง๋ง ํ๊ทธ๋ pre์ด๋ฏ๋ก ํด๋น ์ฌํญ์ด ์์ */
#test1 p:last-child {
background: orange;
color: white;
}
/* 2์ ๋ฐฐ์๋ค์ธ ํ๊ทธ๋ค๋ง ์ ํ */
#test1 p:nth-child(2n) {
background: yellowgreen;
color : white;
}
/* ๋ค์์ 4๋ฒ์งธ ํ๊ทธ์ธ 'ํ
์คํธ3'์ ์ ์ฉ */
#test1 p:nth-last-child(4) {
background: skyblue;
color : white;
}
<div id="test1">
<p>ํ
์คํธ1</p>
<p>ํ
์คํธ2</p>
<p>ํ
์คํธ3</p>
<p>ํ
์คํธ4</p>
<p>ํ
์คํธ5</p>
<pre>ํ
์คํธ6</pre>
</div>
'ํ๊ทธ'๋ก ๊ตฌ๋ถ
์ ํ์:first-of-type { ์ค์ ๋ด์ฉ }
: (ํด๋น ํ์
์) ํ์ ๊ด๊ณ ํ๊ทธ ์ค ์ฒซ ๋ฒ์งธ ํ๊ทธ ์ ํ
์ ํ์:last-of-type { ์ค์ ๋ด์ฉ }
: (ํด๋น ํ์
์) ํ์ ๊ด๊ณ ํ๊ทธ ์ค ๋ง์ง๋ง ํ๊ทธ ์ ํ
์ ํ์:nth-of-type(xn) { ์ค์ ๋ด์ฉ }
: (ํด๋น ํ์
์) ํ์ ๊ด๊ณ ํ๊ทธ ์ค ์์์ x์ ๋ฐฐ์ ํ๊ทธ ์ ํ
์ ํ์:nth-last-of-type(x) { ์ค์ ๋ด์ฉ }
: (ํด๋น ํ์
์)ํ์ ๊ด๊ณ ํ๊ทธ ์ค ๋ค์์ x๋ฒ์งธ ํ๊ทธ ์ ํ
#test2 p:first-of-type {
background-color: azure;
color: red;
}
#test2 p:last-of-type {
background-color: orange;
color : white;
}
#test2 p:nth-of-type(2n) {
background: yellowgreen;
color : white;
}
/* ๋ค์์ 3๋ฒ์งธ ํ๊ทธ์ธ 'ํ
์คํธ3'์ ์ ์ฉ๋จ */
#test2 p:nth-last-of-type(3) {
background: skyblue;
color : white;
}
<div id="test2">
<p>ํ
์คํธ1</p>
<p>ํ
์คํธ2</p>
<p>ํ
์คํธ3</p>
<p>ํ
์คํธ4</p>
<p>ํ
์คํธ5</p>
<pre>ํ
์คํธ6</pre>
</div>
์ ํ์ p::first-letter { ์ค์ ๋ด์ฉ }
: ์ฒซ ๋ฒ์งธ ๊ธ์ ์ ํ
์ ํ์ p::first-line { ์ค์ ๋ด์ฉ }
: ์ฒซ ๋ฒ์งธ ์ค ์ ํ
์ ํ์ p::after { ์ค์ ๋ด์ฉ }
: ํ๊ทธ ๋ค์ ์์นํ๋ ๊ณต๊ฐ์ ์ ํ
์ ํ์ p::before { ์ค์ ๋ด์ฉ }
: ํ๊ทธ ์์ ์์นํ๋ ๊ณต๊ฐ์ ์ ํ
์ ํ์ p::selection { ์ค์ ๋ด์ฉ }
: ์ฌ์ฉ์๊ฐ ๋๋๊ทธํ ๊ธ์ ์ ํ
counter-increment
: ํ๊ทธ๋ณ๋ก ์๋ ๋ฒํธ๋ฅผ ๋งค๊ฒจ์ฃผ๋ ์์ฑ
#test3 p::first-letter {
font-size: 2em;
}
#test3 p::first-line {
background: yellow;
}
#test3 p::after {
content : "@@@ ํ๊ทธ ๋ค์ ์ถ๊ฐ @@@";
}
#test3 p {
counter-increment: num;
}
#test3 p::before {
content : counter(num) "! ";
}
#test3 p::selection {
background: pink; /* ๊ธ์๋ฅผ ๋๋๊ทธํ๋ฉด ํํฌ์ */
color: white;
}
<div id="test3">
<p>
์ถ์ด ๋ฐํํ๊ธฐ ์ํ์ฌ, ...
</p>
์ ํ์:not(:nth-child(x)) { ์ค์ ๋ด์ฉ }
: x๊ฐ ์๋ ํ๊ทธ ์ ํ
#test4 p:nth-child(2n-1) {
background: wheat;
}
#test4 p:not(:nth-child(2n-1)) { /* 2n-1์ด ์๋ ๊ฒ์ ํ์ */
background: orange;
}
<div id="test4">
<p>ํ
์คํธ1</p>
<p>ํ
์คํธ2</p>
<p>ํ
์คํธ3</p>
<p>ํ
์คํธ4</p>
<p>ํ
์คํธ5</p>
</div>
๐โโ๏ธ ๊ธฐ๋ณธ์ ์ผ๋ก CSS ์์ฑ์ ์์์๋ถํฐ ์๋๋ก ์ ์ฉ๋์ง๋ง, ๊ฐ์ ํ๊ทธ์ ์ฌ๋ฌ ๊ฐ์ CSS ์์ฑ์ด ์ ์ฉ ๋ ๊ฒฝ์ฐ ์ฐ์ ์์์ ๋ฐ๋ผ ์คํ์ผ์ด ์ ์ฉ
ํ๊ทธ ์ ํ์
๐ ํด๋์ค ์ ํ์
๐ ์์ด๋ ์ ํ์
๐ ์ธ๋ผ์ธ ์คํ์ผ
๐ !important
์์๋ก ์ฐ์ ์์๋ฅผ ๊ฐ์ง
๐โโ๏ธ ์คํ์ผ(style)์ด๋,
HTML์์๋ฅผ ๋์์ธํ๊ธฐ ์ํ ๊ฐ๋
๐โโ๏ธ HTML <head>์ ์ธ๋ถ ์คํ์ผ ์ํธ ๋งํฌ ์ค์ (๋ฏธ๋ฆฌ ํด๋น ๊ฒฝ๋ก์ CSSํ์ผ ์์ฑ)
<link href="../resources/css/font.css" rel="stylesheet" type="text/css"> <!-- text/css : MIME type -->
์ ํ์ { font-family : ๊ธ๊ผด์ด๋ฆ; }
/* font.css */
#ff1 { font-family : "๊ถ์์ฒด";}
#ff2 { font-family : "๋์์ฒด";}
#ff3 { font-family : "์๋๊ธ๊ผด", "๊ตด๋ฆผ์ฒด";}
/* ์ ์ฉ๋ ์ ์๋ ๊ธ๊ผด์ด ์์ ๊ฒฝ์ฐ, ๊ทธ ๋์ฒด ๊ธ๊ผด์ ๋ค์ ์ ์ด ๋์ ์ ์ฉ */
<p id="ff1">๊ธ๊ผด ๋ณ๊ฒฝ ํ
์คํธ1</p>
<p id="ff2">๊ธ๊ผด ๋ณ๊ฒฝ ํ
์คํธ2</p>
<p id="ff3">๊ธ๊ผด ๋ณ๊ฒฝ ํ
์คํธ3</p>
๐โ ์ ๊น ! ํฐํธ๋ฅผ ์ด๋ป๊ฒ ์ค์ ํ๋์?
Google Fonts
์์ ์ฌ์ฉํ ํฐํธ๋ฅผ ๊ณ ๋ฅธ ๋ค, ์๋์์ ์์ธํ ์นดํ ๊ณ ๋ฆฌ๊น์ง Select- ์ ์์ค๋ HTMLํ์ผ์ <HEAD>์ ๊ธฐ์ฌ, ์๋ ์์ค๋ CSSํ์ผ์ ๊ธฐ์ฌ
- (๋ค๋ฅธ ํฐํธ ์ฌ์ดํธ์์๋ ๋์ผํ ๋ฐฉ๋ฒ)
/* font.css */
#web-font { font-family: 'Roboto Mono', monospace; }
<head>
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@300&display=swap" rel="stylesheet">
</head>
<body>
<p id="web-font">font style test</p>
</body>
์ ํ์ { font-size : ํฌ๊ธฐ; }
/* font.css */
#size1 { font-size : 30px;}
#size2 { font-size : 2em;}
#size3 { font-size : 150%;}
/* ๋ถ๋ชจ ์์ ul์ ํฌ๊ธฐ ๋ณ๊ฒฝ */
#size4 { font-size : 200%; } /* ul์ ์ฌ์ด์ฆ ํฌ๊ธฐ ์ ์ฉ */
#size5 { font-size : 30px; } /* ๋ถ๋ชจ์์์ ํฌ๊ธฐ์์ ๋ ์ ์ฉ */
#size6 { font-size : 2em; }
#size7 { font-size : 150%; }
<ul>
<li id="size1">๊ณ ์ ํฌ๊ธฐ px ํ
์คํธ</li>
<li id="size2">๊ฐ๋ณํฌ๊ธฐ em ํ
์คํธ</li>
<li id="size3">๊ฐ๋ณํฌ๊ธฐ % ํ
์คํธ</li>
</ul>
<ul id="size4">
<li id="size5">๊ณ ์ ํฌ๊ธฐ px ํ
์คํธ</li>
<li id="size6">๊ฐ๋ณํฌ๊ธฐ em ํ
์คํธ</li>
<li id="size7">๊ฐ๋ณํฌ๊ธฐ % ํ
์คํธ</li>
</ul>
๐ Ref.
* em : ํด๋น ํฐํธ์ ๋๋ฌธ์ M์ ๋๋น๋ฅผ ๊ธฐ์ค์ผ๋ก ํจ. ๋ถ๋ชจ ์์์ ํฌ๊ธฐ๋ฅผ ๊ธฐ์ค์ผ๋ก ๋ฐฐ์๋ฅผ ์๋ฏธ.
ex) 1.5em์ 1.5๋ฐฐ
* rem : ์ต์์์ ๋ถ๋ชจ ์์์ ํฌ๊ธฐ ๊ธฐ์ค์ผ๋ก ๋ฐฐ์๋ฅผ ์๋ฏธ.
* % : ๊ธฐ๋ณธ ๊ธ๊ผด์ ํฌ๊ธฐ์ ๋ํ์ฌ ์๋์ ์ธ ๊ฐ์ ๊ฐ์ง (์ ๋ ํฌ๊ธฐ)
* px : Pixels, ํ์์ฅ์น(๋ชจ๋ํฐ)์ ๋ฐ๋ผ์ ์๋์ ์ธ ํฌ๊ธฐ๋ฅผ ๊ฐ์ง
* pt : Points, ๊ธฐ๋ณธ ์ง์ ๋ ํฌ๊ธฐ๋ฅผ ๊ฐ์ง. 1 ํฌ์ธํธ๋ 1/72 ์ธ์น
์ ํ์ { font-weight : normal | bold | bolder | lighter | 100 | 400 | 900; }
/* font.css */
#fw1 { font-weight: bold;}
#fw2 { font-weight: lighter;}
#fw3 { font-weight: bolder;} /* bold๋ณด๋ค ์ฝ๊ฐ ๋ ๊ตต์ */
#fw4 { font-weight: 500;} /* 100 - 900๊น์ง์ ๋ฒ์ (100 : ์์ / 900 : ๋๊บผ์) */
<ul>
<li id="fw1">๊ตต์ ๊ธ๊ผด๋ก ๋ณ๊ฒฝ</li>
<li id="fw2">์๋ ๊ตต๊ธฐ๋ณด๋ค ๋ ๊ฐ๋๊ฒ</li>
<li id="fw3">์๋ ๊ตต๊ธฐ๋ณด๋ค ๋ ๊ตต๊ฒ</li>
<li id="fw4">์์น๋ก ์กฐ์ ํด๋ณด๊ธฐ</li>
</ul>
์ ํ์ { font-variant : ์์ฑ๊ฐ; }
/* font.css */
#fv { font-variant : small-caps;}
<p>I LOVE YOU</p>
<p id="fv">i love you</p>
์ ํ์ { font-style : normal | italic | oblique; }
/* font.css */
#fs1 { font-style : italic; }
#fs2 { font-style : oblique; }
<ul>
<li id="fs1">italic ๊ธฐ์ธ์ ๊ธ๊ผด</li>
<li id="fs2">oblique ๊ธฐ์ธ์ ๊ธ๊ผด</li>
</ul>
์ ํ์ { font : font-style font-variant font-weight font-size/line-height font-family; }
/* font.css */
#f1 { font : 16px/25px "๊ถ์์ฒด"; }
#f2 { font : italic bold 20px/20px "๊ณ ๋์ฒด"; }
<ul>
<li id="f1">๊ธ๊ผด ๊ด๋ จ ์คํ์ผ ํ
์คํธ1</li>
<li id="f2">๊ธ๊ผด ๊ด๋ จ ์คํ์ผ ํ
์คํธ2</li>
</ul>
๐โโ๏ธ HTML <head>์ ์ธ๋ถ ์คํ์ผ ์ํธ ๋งํฌ ์ค์ (๋ฏธ๋ฆฌ ํด๋น ๊ฒฝ๋ก์ CSSํ์ผ ์์ฑ)
<link href="../resources/css/textstyle.css" rel="stylesheet" type="text/css">
์์๊ฐ ์ฐธ์กฐ
์ ํ์ { color : ์์๋ช
์๋ฌธ์ด๋ฆ | 16์ง์์ซ์ | rgb๊ฐ | rgba๊ฐ | hsl๊ฐ | hsla๊ฐ; }
#c-name { color : red; }
#c-16 { color : #ff0000; }
#c-rgb { color : rgb(255, 0, 0); }
/* ํฌ๋ช
๋ ์ถ๊ฐ */
#c-rgba { color : rgba(255, 0, 0, 0.5); } /* 0 - 1์ฌ์ด๋ก ํฌ๋ช
๋ ์ง์ */
/* ์์กฐ, ์ฑ๋, ๋ช
๋ */
#c-hsl { color : hsl(360, 100%, 50%); }
#c-hsla { color : hsl(360, 100%, 50%, 0.5); }
์ ํ์ {text-decoration : none | underline | overline | line-through; }
#td1 { text-decoration: none; } /*ํ์ดํผ๋งํฌ ๋ฐ์ค ์์ ๊ธฐ*/
#td2 { text-decoration: underline; } /*ํ
์คํธ์์ญ ์๋ ์ค ๊ธ๊ธฐ*/
#td3 { text-decoration: line-through; } /*ํ
์คํธ์์ญ ์ค๊ฐ์ ์ค ๊ธ๊ธฐ*/
#td4 { text-decoration: overline; } /*ํ
์คํธ์์ญ ์์ ์ค ๊ธ๊ธฐ*/
์ ํ์ { text-transform : none | capitalize | uppercase | lowercase; }
#tt1 { text-transform : none; }
#tt2 { text-transform : capitalize; } /*์๋ฌธ์์ ์ฒซ ๊ธ์๋ง ๋๋ฌธ์๋ก*/
#tt3 { text-transform : uppercase; } /*๋ชจ๋ ์๋ฌธ์๋ฅผ ๋๋ฌธ์๋ก*/
#tt4 { text-transform : lowercase; } /*๋ชจ๋ ์๋ฌธ์๋ฅผ ์๋ฌธ์๋ก*/
์ ํ์ { text-shadow : none | ๊ฐ๋ก๊ฑฐ๋ฆฌ ์ธ๋ก๊ฑฐ๋ฆฌ ๋ฒ์ง์ ๋ ์์; }
#bg {
background-color: black;
margin: 30px; /* ์ธ๋ถ์์ ๊ฐ๊ฒฉ์ ์ผ๋งํผ ๋ ๊ฒ์ธ์ง */
padding: 10px; /* ๋ด๋ถ์์ ๊ฐ๊ฒฉ์ ์ผ๋งํผ ๋ ๊ฒ์ธ์ง */
}
/* ๊ณตํต ์์ฑ์ผ๋ก ์ฌ์ด์ฆ์ ๋๊ป๋ฅผ ์ง์ */
.shadow {
font-size: 100px;
line-height: 30px;
font-weight: 900;
}
/* ๊ทธ๋ฆผ์ ํจ๊ณผ (๊ฐ๋ก, ์ธ๋ก, ๋ฒ์ง, ์์) */
#ts1 {
color : orangered;
text-shadow: 5px 5px orange;
}
#ts2 {
color: white;
text-shadow: 0px 1px 20px #fff;
}
#ts3 {
color:black;
text-shadow: 0px 0px 4px #ccc,
0px -5px 4px #ff3, /*๋
ธ๋*/
2px -10px 6px #fd3, /*์ง๋
ธ๋*/
-2px -15px 11px #f80, /*์ฃผํฉ*/
2px -19px 18px #f20; /*๋นจ๊ฐ*/
}
white-space
: ํ
์คํธ์ ๊ณต๋ฐฑ์ ์ฒ๋ฆฌ
letter-spacing
: ๋ฑ๊ฐ ๊ธ์์ ๊ฐ๊ฒฉ์ ์กฐ์
word-spacing
: ๋จ์ด์ ๋จ์ด ์ฌ์ด ๊ฐ๊ฒฉ์ ์กฐ์
#space1 {
/* ์ฌ๋ฌ ๊ฐ์ ๊ณต๋ฐฑ์ ํ๋๋ก ํ์ */
white-space : normal;
/* ๋ฑ๊ฐ ๊ธ์์ ๊ฐ๊ฒฉ ์กฐ์ */
letter-spacing : 5px;
}
#space2 {
/* ์ฌ๋ฌ ๊ฐ์ ๊ณต๋ฐฑ์ ํ๋๋ก ํ์, ์ค ๋ฐ๊พธ์ง ์๊ณ ํ ์ค ํ์ */
white-space : nowrap;
/* ๋จ์ด ์ฌ์ด์ ๊ฐ๊ฒฉ ์กฐ์ */
word-spacing : 10px;
}
#space3 {
/* ์ฌ๋ฌ ๊ฐ์ ๊ณต๋ฐฑ์ ๊ทธ๋๋ก ํ์ (์์ฑํ ๋๋ก) */
white-space : pre;
}
#space4 {
/* ์ฌ๋ฌ ๊ฐ์ ๊ณต๋ฐฑ์ ํ๋๋ก ํ์, ์์ญ ๋์ด๊ฐ๋ฉด ์๋ ์ค๋ฐ๊ฟ */
white-space : pre-line;
}
#space5 {
/* ์ฌ๋ฌ ๊ฐ์ ๊ณต๋ฐฑ์ ๊ทธ๋๋ก ํ์, ์์ญ ๋์ด๊ฐ๋ฉด ์๋ ์ค๋ฐ๊ฟ */
white-space : pre-wrap;
}
๐โโ๏ธ HTML <head>์ ์ธ๋ถ ์คํ์ผ ์ํธ ๋งํฌ ์ค์ (๋ฏธ๋ฆฌ ํด๋น ๊ฒฝ๋ก์ CSSํ์ผ ์์ฑ)
<link href="../resources/css/paragraph.css" rel="stylesheet" type="text/css">
direction
#p1 { direction : ltr;} /*์ผ์ชฝ์์ ์ค๋ฅธ์ชฝ์ผ๋ก ํ
์คํธ๋ฅผ ํ์*/
#p2 { direction : rtl;} /*์ค๋ฅธ์ชฝ์์ ์ผ์ชฝ์ผ๋ก ํ
์คํธ๋ฅผ ํ์*/
text-align
#p3 { text-align : left;}
#p4 { text-align : right;}
#p5 { text-align : center;}
#p6 { text-align : justify;} /* ์์ชฝ ์ ๋ ฌ */
line-height
#p7 { line-height : normal;}
#p8 { line-height : 30px;}
#p9 { line-height : 1.5em;}
#p10 { line-height : 200%;}
๐โโ๏ธ HTML <head>์ ์ธ๋ถ ์คํ์ผ ์ํธ ๋งํฌ ์ค์ (๋ฏธ๋ฆฌ ํด๋น ๊ฒฝ๋ก์ CSSํ์ผ ์์ฑ)
<link href="../resources/css/liststyle.css" rel="stylesheet" type="text/css">
list-style-type
#default-bullet { list-style-type: disc; } /*์ฑ์ด ์ ๋ชจ์ ๋ถ๋ (๊ธฐ๋ณธ๊ฐ)*/
#circle-bullet { list-style-type: circle;} /*๋น ์ ๋ชจ์ ๋ถ๋ */
#square-bullet { list-style-type: square;} /*์ฑ์ด ์ฌ๊ฐํ ๋ชจ์ ๋ถ๋ */
#none-bullet { list-style-type: none;} /*๋ถ๋ ์์ ๊ธฐ(๊ฐ์ฅ ์์ฃผ ์ฌ์ฉ)*/
list-style-type
#default-number { list-style-type: decimal; } /*1๋ก ์์ํ๋ 10์ง์(๊ธฐ๋ณธ๊ฐ)*/
#zero-number { list-style-type: decimal-leading-zero; } /*์์ 0์ด ๋ถ๋ 10์ง์*/
#lower-rome-number { list-style-type: lower-roman; } /*์๋ฌธ์ ๋ก๋ง ์ซ์*/
#upper-rome-number { list-style-type: upper-roman; } /*๋๋ฌธ์ ๋ก๋ง ์ซ์*/
#lower-alpha { list-style-type: lower-alpha; } /*์ํ๋ฒณ ์๋ฌธ์*/
#upper-alpha { list-style-type: upper-alpha; } /*์ํ๋ฒณ ๋๋ฌธ์*/
list-style-position
#bullet-inside { list-style-position: inside;}
#bullet-outside { list-style-position: outside;} /* ๊ธฐ๋ณธ๊ฐ */
list-style-image
#image-bullet { list-style-image: url("../images/circle.png");}
body { background-color : ์์๋ช
| rgb | rgba | hsl | hsla | 16์ง์; }
body {
/* ์์๋ช
*/
background-color: pink;
/* RGB(์ ๋
น์ฒญ) */
background-color: rgb(255, 192, 203);
background-color: rgba(255, 192, 203, 0.5);
/* HSL(์์กฐ, ์ฑ๋, ๋ช
๋) */
background-color: hsl(350, 100%, 88%);
background-color: hsla(350, 100%, 88%, 0.5);
/* Hex Code(16์ง์) */
background-color: #FFC0CB;
}
#div-bg {
background-color: white;
}
.div-test {
background-color: white;
/* ์ธ๋ถ ์ฌ๋ฐฑ */
margin : 30px;
/* ๋ด๋ถ ์ฌ๋ฐฑ */
padding : 20px;
/* ํ
๋๋ฆฌ ์ ์ ์ ์ผ๋ก */
border : 5px dashed black;
}
background-clip
#div1 { background-clip: border-box; }
#div2 { background-clip: padding-box; }
#div3 { background-clip: content-box; }
background-image
background-repeat
: ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง์ ๋ฐ๋ณต ๋ฐฉ๋ฒ ์ง์
background-size
: ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง์ ํฌ๊ธฐ ์ง์
background-position
: ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง์ ์์น ์ค์
#bg-img {
height: 800px;
border : 1px solid black;
background-image: url("../resources/images/bgsample.PNG");
/* ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง์ ๋ฐ๋ณต ๋ฐฉ๋ฒ ์ง์ */
/* ๋ฐ๋ณต (๊ธฐ๋ณธ) */
background-repeat: repeat;
/* ๊ฐ๋ก๋ก๋ง ๋ฐ๋ณต */
background-repeat: repeat-x;
/* ์ธ๋ก๋ก๋ง ๋ฐ๋ณต */
background-repeat: repeat-y;
/* ๋ฐ๋ณต ์์ */
background-repeat: no-repeat;
/* ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง์ ํฌ๊ธฐ ์ง์ */
/* ์๋ ํฌ๊ธฐ */
background-size: auto;
/* ์์ ์์ ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง๊ฐ ๋ค ๋ค์ด์ค๋๋ก ์ด๋ฏธ์ง๋ฅผ ํ๋/์ถ์ */
background-size: contain;
/* ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง๋ก ์์๋ฅผ ๋ชจ๋ ๋ฎ์ ์ ์๋๋ก ์ด๋ฏธ์ง๋ฅผ ํ๋/์ถ์ */
background-size: cover;
/* ๊ณ ์ ํฌ๊ธฐ ์ง์ */
background-size: 150px 100px;
/* ์๋ ํฌ๊ธฐ ์ง์ */
background-size: 80% 80%;
/* ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง์ ์์น ์ค์ */
background-position: left top;
background-position: right top;
background-position: center top;
background-position: left bottom;
background-position: right bottom;
background-position: center bottom;
background-position: left center;
background-position: right center;
background-position: center center;
background-position: 30px 50px;
/* ์คํฌ๋กค ์ฌ๋ถ */
background-attachment: scroll;
background-attachment: fixed;
border-style:none
.border-test1 {
border-style:none;
}
border-style:hidden
box-shadow
.border-test2 {
border-style:hidden;
/* ์ํ๊ฑฐ๋ฆฌ ์์ง๊ฑฐ๋ฆฌ ํ๋ฆผ์ ๋ ๋ฒ์ง์ ๋ */
box-shadow:5px 5px 3px 2px gray;
}
border-style:ridge
box-shadow
.border-test9 {
border-style:ridge;
box-shadow:5px 5px 3px 2px gray;
}
border-style:dotted
.border-test3 {
border-style:dotted;
}
border-style:dashed
border-top-color
: ํ
๋๋ฆฌ์ ํ ๋ถ๋ถ์ ์ ์ง์
.border-test4 {
border-style:dashed;
border-top-color:blue;
}
border-style:double
border-color
: ์ ์ฒด ํ
๋๋ฆฌ์ ์ ์ง์
.border-test5 {
border-style:double;
border-color:blue;
}
border-style:groove
border-top-left-radius
.border-test6 {
border-style:groove;
border-top-left-radius:50px;
}
border-style:inset
border-bottom-right-radius
.border-test7 {
border-style:inset;
border-bottom-right-radius:50px;
}
border-style:outset
border-bottom-right-radius
.border-test8 {
border-style:outset;
border-top-left-radius:50px;
border-bottom-right-radius:50px;
}
border-style:solid
border-bottom-width
.border-test10 {
border-style:solid;
border-bottom-width : 10px;
}
border: ๋๊ป ์คํ์ผ ์์๊ฐ
.border-test11 {
border-top : 5px double blue;
border-left : 1px dotted black;
border-right : 1px dashed blue;
border-bottom : 5px solid black;
}
๐โโ๏ธ ๋ ์ด์์(layout)์ด๋,
ํน์ ๊ณต๊ฐ์ ์ฌ๋ฌ ๊ตฌ์ฑ ์์๋ฅผ ๋ณด๊ธฐ ์ข๊ฒ ํจ๊ณผ์ ์ผ๋ก ๋ฐฐ์นํ๋ ์์
- ๋ธ๋ญ ์์ : ํ ์ค ์ ์ฒด๋ฅผ ์ฐจ์งํ๋ ์์. ํ ์ค์ ์ฌ๋ฌ ์์๊ฐ ์ฌ ์ ์๋ ์์.
ex) div, hn, p, pre, hr, ul, ol, form, table, ... ๋ฑ๋ฑ- ์ธ๋ผ์ธ ์์ : ํ ์ค์์ ์ผ๋ถ๋ถ๋ง ์ฐจ์งํ๋ ์์. ํ ์ค์ ์ฌ๋ฌ ์์๊ฐ ์ฌ ์ ์๋ ์์.
ex) span, img, input, label, button, textarea, br(๊ฐํ), ... ๋ฑ๋ฑ
๋ธ๋ญ ์์์ ์ธ๋ผ์ธ ์์์ ์์ฑ์ ๋ณ๊ฒฝํ์ฌ ๋ฐฐ์น ๋ฐฉ์์ ๋ณ๊ฒฝ
display: inline
.block-test1 { display: inline; }
/* ์ธ๋ผ์ธ ์์๋ก ๋ณ๊ฒฝ๋๋ฉด์ width์ height ์์ฑ์ด ๋ฌด์*/
display: block
.block-test2 { display: block; }
/* span์ด์ง๋ง div์ฒ๋ผ ๋ณด์ */
display : inline-block
.block-test3 { display : inline-block; }
/* ์์ญ์ inline, ๋ด์ฉ์ block */
padding
: ํ
๋๋ฆฌ์ ์ปจํ
์ธ ์์ญ ์ฌ์ด์ ๊ฑฐ๋ฆฌ๋ฅผ ์กฐ์ ํ๋ ์์ฑ
padding-top/right/bottom/left
.test1 {
padding: 100px;
padding: 100px 70px 50px 30px; /* ์, ์ค๋ฅธ์ชฝ, ์๋, ์ผ์ชฝ ์์ผ๋ก ๊ฐ๊ฐ ํฌ๊ธฐ ์ง์ ๊ฐ๋ฅ */
padding: 100px 50px; /* ์์๋, ์์๋ง ์ง์ ๋ ๊ฐ๋ฅ*/
}
.test2 {
padding-top: 50px; /* padding์ ์์๋ง ์ค์ */
padding-left: 100px; /* padding์ ์ผ์ชฝ์๋ง ์ค์ */
}
margin
: ์์๋ค ๊ฐ์ ๊ฐ๊ฒฉ์ ์กฐ์ ํ๋ ์์ฑ
.test3 {
margin: 50px; /* ๋ค๋ฅธ ์์๋ค๊ณผ์ ๊ฑฐ๋ฆฌ๊ฐ ์๊น */
margin: 100px 70px 50px 30px;
margin: 100px 50px;
}
.test4 {
margin-bottom: 50px; /* margin์ ์๋์๋ง ์ค์ (์๋์ ๊ณต๊ฐ ์๊น)*/
margin-left: 50px;
}
๐โโ๏ธ position ์์ฑ
- static : ์ผ๋ฐ์ ์ธ ๋ฌธ์ ํ๋ฆ์ ๋ฐ๋ผ ๋ฐฐ์น(๊ธฐ๋ณธ ๊ฐ). top, right, bottme, left ์์ฑ์ด ์๋ฌด๋ฐ ์ํฅ X
- relative : ์ผ๋ฐ์ ์ธ ๋ฌธ์ ํ๋ฆ์ ๋ฐ๋ผ ๋ฐฐ์น. ์๊ธฐ ์์ ๊ธฐ์ค์ผ๋ก top, right, bottom, left์ ๊ฐ์ ๋ฐ๋ผ ์คํ์ ์ ์ฉ.
- absolute : ์ผ๋ฐ์ ์ธ ๋ฌธ์ ํ๋ฆ์์ ์ ์ธ๋๋ฉฐ ๊ณต๊ฐ๋ ์ฐจ์งํ์ง์์. ๊ฐ์ฅ ๊ฐ๊น์ด ์์น ์ง์ ์กฐ์ ์์์ ๋ํด ์๋์ ์ผ๋ก ๋ฐฐ์น ๋๋ฉฐ top, right, bottom, left์ ๊ฐ์ด ์์น๋ฅผ ๊ฒฐ์ ํจ
- fixed : ์ผ๋ฐ์ ์ธ ๋ฌธ์ ํ๋ฆ์์ ์ ์ธ๋๋ฉฐ ๊ณต๊ฐ๋ ์ฐจ์งํ์ง ์์. ํด๋น ์์๊ฐ ๋ชจ๋ ํ์ด์ง์ ๊ฐ์ ์์น์ ์ถ๋ ฅ.
position: static
position: relative
#first {
position: static; /* ๊ธฐ๋ณธ๊ฐ */
top: 20px; /* ๊ธฐ๋ณธ๊ฐ์ด๋ฏ๋ก ๋ณํ X */
left: 20px;
}
#second {
position: relative; /* relative๋ก position ๋ณ๊ฒฝ */
top: 20px;
left: 20px;
}
#third {
position: relative;
bottom: 20px;
right: 20px;
}
position: absolute
.positioning {
border : 1px solid black;
}
.outer { /* second์ third๊ฐ body๊ฐ ์๋ outer๋ฅผ ๊ธฐ์ค์ผ๋ก ์ด๋(์์น ์ง์ ์์) */
position: relative;
}
.first {
width: 300px;
height: 300px;
background-color: yellow;
}
.second {
width: 200px;
height: 200px;
background-color: yellowgreen;
position: absolute; /* ๊ฐ์ฅ ๊ฐ๊น์ด ์์น ์ง์ ์กฐ์ ์์์ ๋ํด ์๋์ ์ผ๋ก ๋ฐฐ์น */
top: 50px;
left: 50px;
}
.third {
width: 100px;
height: 100px;
background-color: red;
position: absolute;
top: 100px;
left: 100px;
}
<div class="outer"> <!-- ์๋์ ์ผ๋ก ๊ธฐ์ค์ด ๋ div๋ฅผ ์ค์ -->
<div class="positioning first"></div>
<div class="positioning second"></div>
<div class="positioning third"></div>
</div>
.fixed-area { /* ์คํฌ๋กค์ ์ด๋ํด๋ ์์น๊ฐ ํญ์ ๊ณ ์ ๋์ด์์ */
width: 100px;
height: 100px;
position: fixed;
left: 500px;
top: 500px;
}
ํ์ด์ง์ ํน์ ์์๋ฅผ ๋ณด์ด๊ฑฐ๋ ๋ณด์ด์ง ์๊ฒ ํ๋ ์์ฑ
visibility: hidden
: ํ์ด์ง ๊ณต๊ฐ ์ฐจ์ง O
display: none
: ํ์ด์ง ๊ณต๊ฐ ์ฐจ์ง X
.vis-test1 { background-color: red;}
.vis-test2 {
background-color: yellow;
visibility: hidden; /* ์๋ฆฌ๋ ๊ทธ๋๋ก ์ฐจ์งํ๋, ๋์ ๋ณด์ด์ง ์์ */
display: none; /* ์๋ฆฌ ์ฐจ์ง๋ ํ์ง์๊ณ ์ฌ๋ผ์ง */
}
.vis-test3 { background-color: green;}
z-index
: ํ์ด์ง ์์ ์์๋ค์ ์์๋๋ก ์๋ก ์๋ ์์ฑ
.wrap { /* z-test๋ค์ ์์น ์ง์ ์์ */
position: relative;
}
.z-test {
width: 150px;
height: 100px;
border: 1px solid black;
position: absolute;
}
.z-test1 {
background-color: yellow;
top: 100px;
left: 100px;
z-index: 100;
/* z-index์ ์์น๋ฅผ ๋๊ฒ ์ง์ ํ๋ฉด ๋งจ ์๋์์ ๋งจ ์๋ก ์ฌ๋ผ์ค๊ฒ ๋จ */
}
.z-test2 {
background-color: green;
top: 50px;
left: 50px;
z-index: 50;
/*z-test1์ z-index ๋ณด๋ค๋ ์์น๊ฐ ์ ์ผ๋ฏ๋ก ์์๊ฐ ์๋, ์์น๊ฐ ์๋ z-test3๋ณด๋ค๋ ์ */
}
.z-test3 {
background-color: red;
top: 0px;
left: 0px;
}
float
: ํ์ด์ง ๋ด์ ์์์ ์์น๋ฅผ ์ผ์ชฝ์ด๋ ์ค๋ฅธ์ชฝ์ผ๋ก ์ง์ ํ๋ ์์ฑ
.float-test {
border: 1px solid black;
width: 150px;
height: 100px;
float: right; /* ์ค๋ฅธ์ชฝ์์๋ถํฐ ์ผ์ชฝ์ผ๋ก ํ๋ฅด๋ฏ์ด ์์น ์ค์ */
}
display: flex
: ์ํ ์ ๋ ฌ
flex-direction
: ๋ฐฐ์น ๋ฐฉํฅ
flex-wrap
: ์ค๋ฐ๊ฟ
justify-content
: ์ํ ๋ฐฉํฅ ๋ง์ถค
align-items
: ์์ง ๋ฐฉํฅ ๋ง์ถค
.item {
background-color: lightblue;
color : white;
margin: 10px;
padding: 10px;
}
.container {
/* ๋ถ๋ชจ ์์(container)์ display : flex; ์ถ๊ฐ ์ ์ํ ์ ๋ ฌ */
display: flex;
/* ๋ฐฐ์น ๋ฐฉํฅ */
flex-direction: row-reverse; /* ์ค๋ฅธ์ชฝ ์ ๋ ฌ, ์์ ๋ฐ๋ */
flex-direction: column;
flex-direction: column-reverse;
flex-direction: row; /* ๊ธฐ๋ณธ๊ฐ */
/* ์ค๋ฐ๊ฟ */
flex-wrap: nowrap; /* ํ๋ฉด์ ์ค์ฌ๋ ์ค๋ฐ๊ฟ X */
flex-wrap: wrap-reverse; /* ํ๋ฉด์ ์ค์ด๋ฉด ์ค๋ฐ๊ฟ O, ์์ ๋ฐ๋ */
flex-wrap: wrap; /* ๊ธฐ๋ณธ๊ฐ */
/* ์ํ ๋ฐฉํฅ ๋ง์ถค */
justify-content: flex-end; /* ๋ ์ชฝ์ ๋ง์ถฐ ์ ๋ ฌ */
justify-content: center; /* ๊ฐ์ด๋ฐ๋ก ์ ๋ ฌ */
justify-content: space-between; /* ์์ชฝ ์ ๋ ฌ, ๊ฐ ์ฌ๋ฐฑ์ด ๋์ผ */
justify-content: space-around; /* ๊ฐ ์ฌ๋ฐฑ์ด ๋์ผ */
justify-content: flex-start; /* ๊ธฐ๋ณธ๊ฐ */
/* vh๋ ๋ทฐ ํฌํธ์ ๋์ด ๊ธฐ์ค ๋จ์ */
height: 100vh; /* ํ๋ฉด์ ๊ฝ ์ฐจ๊ฒ ๋ง์ถ ํฌ๊ธฐ */
/* align-item : ์์ง ๋ฐฉํฅ ๋ง์ถค */
align-items: flex-start; /* ๋งจ ์์ ์ ๋ ฌ */
align-items: flex-end; /* ๋งจ ์๋์ ์ ๋ ฌ */
align-items: center; /* ๊ฐ์ด๋ฐ์ ์ ๋ ฌ */
align-items: stretch; /* ๊ธฐ๋ณธ๊ฐ (๋ถ๋ชจ์ ํฌ๊ธฐ์ ๋ง์ถค) */
}
display: grid
: 2์ฐจ์์ผ๋ก ์ํ ์์ง์ ๋์์ ์์ญ ๋๋๊ธฐ ๊ฐ๋ฅ
grid-template-columns
: ๊ทธ๋ฆฌ๋ ์์ดํ
๋๋น
grid-template-rows
: ๊ทธ๋ฆฌ๋ ์์ดํ
๋์ด
gap
: ๊ทธ๋ฆฌ๋ ์์ดํ
์ฌ์ด์ ์ฌ๋ฐฑ
grid-column
: ์ปฌ๋ผ(๊ฐ๋ก) ์กฐ์
grid-row
: ๋ก์ฐ(์ธ๋ก) ์กฐ์
grid-area
: ํ๋ฒ์ ์์ญ ๋๋๊ธฐ
.item {
background-color: lightcoral;
color: white;
padding: 10px;
margin: 10px;
}
.container {
display: grid;
/* ๊ทธ๋ฆฌ๋ ์์ดํ
๋๋น */
grid-template-columns: 200px 200px 200px; /* 3๊ฐ ์์ฑ = 3๊ฐ์ ํ */
grid-template-columns: 100px 200px auto; /* auto๋ง ๊ณ ์ ์ด ๋์ด์์ง ์๊ณ ํ๋ฉด ๋๋น์ ๋ฐ๋ผ ๋ฌ๋ผ์ง */
/* fr(fraction) ๋จ์๋ก ์ฒ๋ฆฌ */
grid-template-columns: 1fr 1fr 1fr; /* 1:1:1์ ๋น์จ */
/* ๋ฐ๋ณต๋๋ ํจํด์ด ์๋ค๋ฉด repeat ์ฌ์ฉ */
grid-template-columns: repeat(3, 1fr); /* ์์ ๊ฐ์ ๊ฒฐ๊ณผ */
/* ๊ทธ๋ฆฌ๋ ์์ดํ
์ฌ์ด์ ์ฌ๋ฐฑ */
row-gap: 20px;
column-gap: 10px;
gap: 20px 10px;
gap: 20px; /* row์ column์ gap ๊ฐ์ด ๊ฐ๋ค๋ฉด ํ๋๋ง ์
๋ ฅ OK */
/* ๊ทธ๋ฆฌ๋ ์์ดํ
๋์ด */
grid-template-rows: 200px 200px 300px;
/* row ๊ฐ์๋ฅผ ๋ฏธ๋ฆฌ ์ ์ ์์ ๋ */
grid-auto-rows: 200px;
}
.item:nth-child(1) {
/* column ์์/๋ ์ค์ */
grid-column-start: 1;
grid-column-end: 3;
/* column ์์/๋ ์ค์ ํ๋ฒ์ */
grid-column: 1/3; /* ์์ ๋์ผ */
grid-column: 1/span 2; /* ์์ ๋์ผ */
/* row ์์/๋ ์ค์ */
grid-row-start: 1;
grid-row-end: 3;
/* row ์์/๋ ์ค์ ํ๋ฒ์ */
grid-row: 1/4;
grid-row: 1/span 2; /* grid-row: 1/2์ ๊ฐ์ */
/* ํ๋ฒ์ ์์ญ ๋๋๊ธฐ */
/* row์์/column์์/row๋/column๋ */
grid-area: 1/1/3/3;
}