Index
Index1. id์ class ํน์ง1.1 About id1.2 About class2. CSS์์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ3. ์ฐ์ ์์
์ ํ์ id์ class ํ๊ทธ๋ HTML, CSS ๊ทธ๋ฆฌ๊ณ Javascript๊น์ง ์ฌ์ฉ๋ฉ๋๋ค. HTML์์๋ ์ ์ด๋ ํ
์คํธ์ ์์ฑ์ ์ ํด์ฃผ๊ฑฐ๋ CSS์ Javascript์์๋ ํ๊ทธ ๋ณ๋ก ํน์ง์ ์ ํด์ค ๋ ์ฌ์ฉํ๋ ์ ๋ง ๊ด๋ฒ์ํ๊ฒ ์ฐ์ด์ฃ . id์ class์ ํน์ง, css์์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ, ๊ทธ๋ฆฌ๊ณ ์ฐ์ ์์๋ฅผ ํจ๊ป ์ดํด๋ณผ๊น์.
1. id์ class ํน์ง
1.1 About id
id ์์ฑ์ ํ์ด์ง์ ์๋ ํด๋น ์์๋ฅผ ์ ์ผํ๊ฒ ์๋ณํ ๋ ์๋๋ค. ์ฃผ์ ์ฌํญ์ผ๋ก๋ ๊ฐ์ ํ์ด์ง ์์ id๋ ๋จ ํ ๊ฐ๋ง ์กด์ฌํด์ผ ํฉ๋๋ค. ๋ id ์ด๋ฆ์ ์ํ๋ฒณ ๋๋ '_'์ผ๋ก ์์ํด์ผ ํฉ๋๋ค. id๋ฅผ ์ด์ฉํด css์ javascript์์ ํ์ฉํ ์ ์์ผ๋ ์ค์ํ ์์ฑ ์ค ํ๋์
๋๋ค. ๊ฐ์ธ ํ๋ก์ ํธ์ผ ๊ฒฝ์ฐ๋ ์๊ด์์ง๋ง ์ฌ๋ฌ ์ฌ๋๋ค๊ณผ ๊ฐ์ด ํ๋ ํ๋ก์ ํธ์์๋ id์ด๋ฆ์ ์ต๋ํ ์ง๊ด์ ์ด๊ณ ๊ฐ๋จ๋ช
๋ฃํ๊ฒ ์ง์ด์ฃผ๋ ๊ฒ๋ ์ค์ํ๋ต๋๋ค.
- CODE
<head> <meta charset="utf-8"> <title>id</title> <style type ="text/css"> #blue { color : blue;} </style> </head> <body> <p>์ด ๋ฌธ๋จ์ ํ๋ฒํ pํ๊ทธ๋ฅผ ์ฌ์ฉํ์์ต๋๋ค.</p> <p id = "blue">์ด ๋ฌธ๋จ์ blue id๋ฅผ ๋ถ์ฌํ์์ต๋๋ค.</p> </body>
- ์คํํ๋ฉด

1.2 About class
class ์์ฑ์ ๋ํ id ์์ฑ๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ํด๋น ์์๋ฅผ ์๋ณํ ๋ ์ฌ์ฉํฉ๋๋ค. ๊ทธ๋ฌ๋ id ์์ฑ์ ํ ํ์ด์ง์ ํ๋๋ง ์กด์ฌํด์ผ ํ๋ ๋ฐ๋ฉด class ์์ฑ์ ํ ํ์ด์ง์ ์ฌ๋ฌ ๊ฐ๊ฐ ์กด์ฌํ ์ ์๊ธฐ ๋๋ฌธ์ ๋์ผํ class ์์ฑ์ด ๋ค์ด๊ฐ ์์๋ค์ ๋์์ ์๋ณํ ์ ์์ต๋๋ค.
class ์์ฑ๋ id ์์ฑ๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก css์ javascript์์ ํ์ฉํ ์ ์์ผ๋ ์์ฃผ ์ค์ํ ์์ฑ ์ค ํ๋์
๋๋ค. class๋ id์ ๋ง์ฐฌ๊ฐ์ง๋ก ์ด๋ฆ์ ์ง์ ๋ ์ง๊ด์ ์ด๊ณ ๊ฐ๋จ๋ช
๋ฃํ๊ฒ ์ ์ด์ฃผ๋ ๊ฒ์ด ์ค์ํฉ๋๋ค.
- CODE
<head> <meta charset="utf-8"> <title>id</title> <style type ="text/css"> .blue { color : blue; } .bic { font-size : 20px; } .upper { text-transform : uppercase; } </style> </head> <body> <p>์ด ๋ฌธ๋จ์ ํ๋ฒํ pํ๊ทธ๋ฅผ ์ฌ์ฉํ์์ต๋๋ค.</p> <p class="blue">์ด ๋ฌธ๋จ์ blue class๋ฅผ ๋ถ์ฌํ์์ต๋๋ค.</p> <p class="blue bic">์ด ๋ฌธ๋จ์ blue, bic class๋ฅผ ๋ถ์ฌํ์์ต๋๋ค.</p> <p class="blue upper">์ด ๋ฌธ๋จ์ blue, bic class๋ฅผ ๋ถ์ฌํ์์ต๋๋ค. </p> </body>
- ์คํํ๋ฉด
ย

2. CSS์์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ
์์ ๊ฐ๋ตํ ์ฝ๋์์๋ ์ ์ถ๊ฐ ๊ฐ๋ฅํ์ง๋ง ์กฐ๊ธ ๋ ์ธ๋ถํํ์ฌ ์ดํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
<h1>h1์ ์ฒซ๋ฒ์งธ</h1> <h1>h1์ ๋๋ฒ์งธ</h1> <h1>h1์ ์ธ๋ฒ์งธ</h1> <h1>h1์ ๋ค๋ฒ์งธ</h1>

์
h1
์ 4๊ฐ ์ ๋ถ๋ฅผ ๋นจ๊ฐ์์ผ๋ก ๋ฐ๊ฟ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. CSS๋ฅผ ์ ์ฉํ๋ 3๊ฐ์ง ๋ฐฉ๋ฒ ์ค์ ์ฐ๋ฆฌ๋ HTML์ <style>
ํ๊ทธ๋ฅผ ์ฌ์ฉํด์ css ์์ฑ์ ๋ฃ์ด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.<head> <style> h1 {color: red;} </style> </head> <body> <h1>h1์ ์ฒซ๋ฒ์งธ</h1> <h1>h1์ ๋๋ฒ์งธ</h1> <h1>h1์ ์ธ๋ฒ์งธ</h1> <h1>h1์ ๋ค๋ฒ์งธ</h1> </body>

h1
๋ชจ๋๊ฐ ๋นจ๊ฐ์์ผ๋ก ๋ณํ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค. ๋ชจ๋ h1
ํ๊ทธ๋ก ์์ฑ์ด ๋์ด ์๊ธฐ ๋๋ฌธ์ ๋ชจ๋ ๋ค๋ฅธ ์์ ์ฃผ๊ณ ์ถ์ ๋์๋ ์๋์ ๊ฐ์ด ํน์ ํ๊ทธ๋ฅผ ์ง์ ํด์ผ ํฉ๋๋ค. ์ด๋ด ๊ฒฝ์ฐ ์ฌ์ฉํ๋ ํ๊ทธ๊ฐ id์
๋๋ค. <head> <style> h1 {color: red} #two {color: yellow} #three {color: green} #four {color: blue} </style> </head> <body> <h1>h1์ ์ฒซ๋ฒ์งธ</h1> <h1 id='two'>h1์ ๋๋ฒ์งธ</h1> <h1 id='three'>h1์ ์ธ๋ฒ์งธ</h1> <h1 id='four'>h1์ ๋ค๋ฒ์งธ</h1> </body>
๋๋ฒ์งธ
h1
id ์ด๋ฆ์ 'two', ์ธ๋ฒ์งธ h1
id ์ด๋ฆ์ 'three', ๋ค๋ฒ์งธ h1
id ์ด๋ฆ์ 'four'๋ก ์ง์ ํด์ฃผ์์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ <style>
์์ ํด๋น id๋ฅผ ๊พธ๋ฉฐ์ฃผ๊ธฐ ์ํ์ฌ two๋ yellow, three๋ green, four๋ blue๋ก ์์์ ์ง์ ํด์ฃผ์์ต๋๋ค. ์ฌ๊ธฐ์ ์ค์ํ ๋ถ๋ถ์ CSS์์ id๋ฅผ ๋ถ๋ฌ์ฌ ๋ #์ ์ด๋ค๋ ๋ถ๋ถ์
๋๋ค.
์ด๋ฒ์๋ ์ฒซ๋ฒ์งธ / ๋๋ฒ์งธ๋ถํฐ ๋ค๋ฒ์งธ๊น์ง ์์ ๋ฌ๋ฆฌํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
<head> <style> h1 {color: red} #two {color: green} #three {color: green} #four {color: green} </style> </head> <body> <h1>h1์ ์ฒซ๋ฒ์งธ</h1> <h1 id='two'>h1์ ๋๋ฒ์งธ</h1> <h1 id='three'>h1์ ์ธ๋ฒ์งธ</h1> <h1 id='four'>h1์ ๋ค๋ฒ์งธ</h1> </body>

๋๋ฒ์งธ๋ถํฐ ๋ค๋ฒ์งธ๊น์ง ๋ค ๊ฐ์ ์์์๋ ๋ถ๊ตฌํ๊ณ ํ๋ํ๋ ์ง์ ์ ํด์ฃผ๋ ๊ฒ์ ๋นํจ์จ์ ์
๋๋ค. ์ด๋ด ๊ฒฝ์ฐ ์ฌ์ฉํ๋ ๊ฒ์ด class์
๋๋ค. class๋ ๋ฌถ์ด์ ์ ์ฉํ ์ ์์ต๋๋ค.
<head> <style> h1 {color: red} .yellowgreen {color: yellowgreen} </style> </head> <body> <h1>h1์ ์ฒซ๋ฒ์งธ</h1> <h1 id='two' class='yellowgreen'>h1์ ๋๋ฒ์งธ</h1> <h1 id='three' class='yellowgreen'>h1์ ์ธ๋ฒ์งธ</h1> <h1 id='four' class='yellowgreen'>h1์ ๋ค๋ฒ์งธ</h1> </body>

๊ฐ ๋ผ์ธ๋ง๋ค class ๋ช
(yellowgreen)์ ์ถ๊ฐํด ์ฃผ์์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ
<style>
ํ๊ทธ์ .yellowgreen์ ๋ถ๋ฌ ์์์ ์ง์ ํด์ฃผ์์ฃ . class๋ id์ ๋ค๋ฅด๊ฒ, ์ (.)
์ class ๋ช
์์ ๋์ด์ผ ํฉ๋๋ค. 3. ์ฐ์ ์์
์๋ ์ฝ๋์ ๊ฐ์ด id์ class๊ฐ ๋์์ ์์ ๊ฒฝ์ฐ์๋ id > class > tag ์์ผ๋ก style ์ ์ฉ์ด ๋ฉ๋๋ค.
<head> <style> h1 {color: red} .yellowgreen {color: yellowgreen} #four {color: skyblue} </style> </head> <body> <h1>h1์ ์ฒซ๋ฒ์งธ</h1> <h1 id='two' class='yellowgreen'>h1์ ๋๋ฒ์งธ</h1> <h1 id='three' class='yellowgreen'>h1์ ์ธ๋ฒ์งธ</h1> <h1 id='four' class='yellowgreen'>h1์ ๋ค๋ฒ์งธ</h1> </body>

h1์ ๋๋ฒ์งธ, ์ธ๋ฒ์งธ, ๋ค๋ฒ์งธ๋ ๋ค ๊ฐ์ class(yellowgreen)์ด์์ต๋๋ค. ์ฌ๊ธฐ์ ๋ง์ง๋ง
h1
์ id ์์ฑ์ style์์ ๋ณ๊ฒฝํด๋ณด์์ต๋๋ค. ๋ค์ ๋งํด, h1
์ ๋ค๋ฒ์งธ๋ class์ style๋, id์ style๋ ์ ์ฉ๋์์ง๋ง ์ฐ์ ์์์ ๋ฐ๋ผ id์ ์์ฑ์ธ skyblue์์ ๋ํ๋ด๊ฒ ๋์์ต๋๋ค.๋ํ ๋์ผํ ์์ฑ์ ์ฌ๋ฌ ํ์ผ์ด๋ class์์ ๋ค์ค์ผ๋ก ์ ์ํ๊ณ ์๋ค๋ฉด ๊ฐ์ฅ ๋์ค์ ์ ์ฉ๋ ํ์ผ์ด๋ class๊ฐ ํด๋น ์์ฑ์ ๋ฎ์ด์ฐ๊ฒ ๋ฉ๋๋ค. ์๋์ ๊ฐ์ ๊ฒฝ์ฐ one์ด๋ผ๋ ํด๋์ค๊ฐ one.css, two.css, three.css ๋ชจ๋ ์ ์ฉ๋์ด ์๋ค๊ณ ํ๋๋ผ๋ three.css๊ฐ ์ ์ฉ๋ฉ๋๋ค.
<html> <head> <link rel="stylesheet" href="/css/one.css"> <link rel="stylesheet" href="/css/two.css"> <link rel="stylesheet" href="/css/three.css"> </head> <body> <h1 class="one">hello world</h1> </body> </html>
ย