CSS ๊ธฐ์ดˆ

CSS ๊ธฐ์ดˆ

1. CSS๋ž€?

CSS(Cascading Style Sheets)๋Š” HTML ์š”์†Œ์˜ ์Šคํƒ€์ผ์„ ์ •์˜ํ•˜๋Š” ์–ธ์–ด์ž…๋‹ˆ๋‹ค.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    CSS์˜ ์—ญํ•                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  โ€ข ์ƒ‰์ƒ, ํฐํŠธ, ํฌ๊ธฐ                                   โ”‚
โ”‚  โ€ข ๋ ˆ์ด์•„์›ƒ, ์œ„์น˜                                     โ”‚
โ”‚  โ€ข ์• ๋‹ˆ๋ฉ”์ด์…˜, ์ „ํ™˜ ํšจ๊ณผ                              โ”‚
โ”‚  โ€ข ๋ฐ˜์‘ํ˜• ๋””์ž์ธ                                      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

2. CSS ์ ์šฉ ๋ฐฉ๋ฒ•

์ธ๋ผ์ธ ์Šคํƒ€์ผ (๊ถŒ์žฅํ•˜์ง€ ์•Š์Œ)

<p style="color: red; font-size: 16px;">๋นจ๊ฐ„ ํ…์ŠคํŠธ</p>

๋‚ด๋ถ€ ์Šคํƒ€์ผ์‹œํŠธ

<!DOCTYPE html>
<html>
<head>
    <style>
        p {
            color: blue;
            font-size: 18px;
        }
    </style>
</head>
<body>
    <p>ํŒŒ๋ž€ ํ…์ŠคํŠธ</p>
</body>
</html>

์™ธ๋ถ€ ์Šคํƒ€์ผ์‹œํŠธ (๊ถŒ์žฅ)

<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <p>์Šคํƒ€์ผ์ด ์ ์šฉ๋œ ํ…์ŠคํŠธ</p>
</body>
</html>
/* style.css */
p {
    color: green;
    font-size: 20px;
}

3. CSS ๋ฌธ๋ฒ•

๊ธฐ๋ณธ ๊ตฌ์กฐ

์„ ํƒ์ž {
    ์†์„ฑ: ๊ฐ’;
    ์†์„ฑ: ๊ฐ’;
}

/* ์˜ˆ์‹œ */
h1 {
    color: blue;
    font-size: 24px;
    text-align: center;
}

์ฃผ์„

/* ํ•œ ์ค„ ์ฃผ์„ */

/*
    ์—ฌ๋Ÿฌ ์ค„
    ์ฃผ์„
*/

4. ์„ ํƒ์ž (Selectors)

๊ธฐ๋ณธ ์„ ํƒ์ž

/* ์ „์ฒด ์„ ํƒ์ž */
* {
    margin: 0;
    padding: 0;
}

/* ํƒœ๊ทธ ์„ ํƒ์ž */
p {
    color: black;
}

/* ํด๋ž˜์Šค ์„ ํƒ์ž */
.highlight {
    background-color: yellow;
}

/* ID ์„ ํƒ์ž */
#header {
    background-color: navy;
}
<p>์ผ๋ฐ˜ ๋ฌธ๋‹จ</p>
<p class="highlight">๊ฐ•์กฐ๋œ ๋ฌธ๋‹จ</p>
<div id="header">ํ—ค๋”</div>

๊ทธ๋ฃน ์„ ํƒ์ž

/* ์—ฌ๋Ÿฌ ์š”์†Œ์— ๊ฐ™์€ ์Šคํƒ€์ผ */
h1, h2, h3 {
    font-family: Arial, sans-serif;
}

.btn, .link, .card {
    cursor: pointer;
}

๊ฒฐํ•ฉ ์„ ํƒ์ž

/* ์ž์† ์„ ํƒ์ž (๋ชจ๋“  ํ•˜์œ„) */
article p {
    line-height: 1.6;
}

/* ์ž์‹ ์„ ํƒ์ž (์ง์ ‘ ์ž์‹๋งŒ) */
ul > li {
    list-style: none;
}

/* ์ธ์ ‘ ํ˜•์ œ ์„ ํƒ์ž (๋ฐ”๋กœ ๋‹ค์Œ) */
h1 + p {
    font-size: 1.2em;
}

/* ์ผ๋ฐ˜ ํ˜•์ œ ์„ ํƒ์ž (๋’ค์— ์žˆ๋Š” ๋ชจ๋“ ) */
h1 ~ p {
    color: gray;
}
<article>
    <p>์ง์ ‘ ์ž์‹</p>
    <div>
        <p>์†์ž ์š”์†Œ</p>  <!-- article p๋Š” ๋‘˜ ๋‹ค ์„ ํƒ -->
    </div>
</article>

<h1>์ œ๋ชฉ</h1>
<p>์ฒซ ๋ฒˆ์งธ ๋ฌธ๋‹จ</p>  <!-- h1 + p ์„ ํƒ -->
<p>๋‘ ๋ฒˆ์งธ ๋ฌธ๋‹จ</p>  <!-- h1 ~ p ์„ ํƒ -->

์†์„ฑ ์„ ํƒ์ž

/* ์†์„ฑ์ด ์žˆ๋Š” ์š”์†Œ */
[disabled] {
    opacity: 0.5;
}

/* ์†์„ฑ๊ฐ’์ด ์ผ์น˜ */
[type="text"] {
    border: 1px solid gray;
}

/* ์†์„ฑ๊ฐ’์œผ๋กœ ์‹œ์ž‘ */
[href^="https"] {
    color: green;
}

/* ์†์„ฑ๊ฐ’์œผ๋กœ ๋๋‚จ */
[href$=".pdf"] {
    color: red;
}

/* ์†์„ฑ๊ฐ’ ํฌํ•จ */
[class*="btn"] {
    cursor: pointer;
}

๊ฐ€์ƒ ํด๋ž˜์Šค ์„ ํƒ์ž

/* ๋งํฌ ์ƒํƒœ */
a:link { color: blue; }      /* ๋ฐฉ๋ฌธ ์ „ */
a:visited { color: purple; } /* ๋ฐฉ๋ฌธ ํ›„ */
a:hover { color: red; }      /* ๋งˆ์šฐ์Šค ์˜ฌ๋ฆผ */
a:active { color: orange; }  /* ํด๋ฆญ ์ค‘ */

/* ํฌ์ปค์Šค */
input:focus {
    border-color: blue;
    outline: none;
}

/* ์ฒซ ๋ฒˆ์งธ/๋งˆ์ง€๋ง‰ */
li:first-child { font-weight: bold; }
li:last-child { border-bottom: none; }

/* n๋ฒˆ์งธ */
tr:nth-child(odd) { background: #f0f0f0; }   /* ํ™€์ˆ˜ */
tr:nth-child(even) { background: #ffffff; }  /* ์ง์ˆ˜ */
tr:nth-child(3) { color: red; }              /* 3๋ฒˆ์งธ */
tr:nth-child(3n) { font-weight: bold; }      /* 3์˜ ๋ฐฐ์ˆ˜ */

/* not (๋ถ€์ •) */
p:not(.special) {
    color: gray;
}

/* ํผ ์ƒํƒœ */
input:disabled { background: #ddd; }
input:checked + label { font-weight: bold; }
input:required { border-color: red; }

๊ฐ€์ƒ ์š”์†Œ ์„ ํƒ์ž

/* ์ฒซ ๊ธ€์ž/์ฒซ ์ค„ */
p::first-letter {
    font-size: 2em;
    font-weight: bold;
}

p::first-line {
    color: blue;
}

/* ์•ž/๋’ค์— ์ฝ˜ํ…์ธ  ์ถ”๊ฐ€ */
.quote::before {
    content: '"';
}

.quote::after {
    content: '"';
}

/* ์˜ˆ์‹œ: ํ•„์ˆ˜ ํ‘œ์‹œ */
.required::after {
    content: ' *';
    color: red;
}

/* ์„ ํƒ ์˜์—ญ */
::selection {
    background: yellow;
    color: black;
}

5. ์ƒ‰์ƒ

์ƒ‰์ƒ ํ‘œํ˜„ ๋ฐฉ๋ฒ•

/* ์ƒ‰์ƒ ์ด๋ฆ„ */
color: red;
color: blue;
color: transparent;

/* HEX (16์ง„์ˆ˜) */
color: #ff0000;      /* ๋นจ๊ฐ• */
color: #f00;         /* ๋นจ๊ฐ• (์ถ•์•ฝ) */
color: #336699;

/* RGB */
color: rgb(255, 0, 0);        /* ๋นจ๊ฐ• */
color: rgb(51, 102, 153);

/* RGBA (ํˆฌ๋ช…๋„) */
color: rgba(255, 0, 0, 0.5);  /* 50% ํˆฌ๋ช… ๋นจ๊ฐ• */

/* HSL (์ƒ‰์ƒ, ์ฑ„๋„, ๋ช…๋„) */
color: hsl(0, 100%, 50%);     /* ๋นจ๊ฐ• */
color: hsla(0, 100%, 50%, 0.5);

๋ฐฐ๊ฒฝ์ƒ‰

.box {
    background-color: #f0f0f0;
    background-color: rgba(0, 0, 0, 0.1);
}

6. ํ…์ŠคํŠธ ์Šคํƒ€์ผ

ํฐํŠธ

.text {
    /* ํฐํŠธ ํŒจ๋ฐ€๋ฆฌ */
    font-family: 'Noto Sans KR', Arial, sans-serif;

    /* ํฐํŠธ ํฌ๊ธฐ */
    font-size: 16px;
    font-size: 1rem;
    font-size: 1.5em;

    /* ํฐํŠธ ๊ตต๊ธฐ */
    font-weight: normal;    /* 400 */
    font-weight: bold;      /* 700 */
    font-weight: 300;       /* light */

    /* ํฐํŠธ ์Šคํƒ€์ผ */
    font-style: normal;
    font-style: italic;

    /* ๋‹จ์ถ• ์†์„ฑ */
    font: italic bold 16px/1.5 Arial, sans-serif;
}

ํ…์ŠคํŠธ

.text {
    /* ์ƒ‰์ƒ */
    color: #333;

    /* ์ •๋ ฌ */
    text-align: left;
    text-align: center;
    text-align: right;
    text-align: justify;

    /* ์žฅ์‹ */
    text-decoration: none;
    text-decoration: underline;
    text-decoration: line-through;

    /* ๋ณ€ํ™˜ */
    text-transform: uppercase;
    text-transform: lowercase;
    text-transform: capitalize;

    /* ๋“ค์—ฌ์“ฐ๊ธฐ */
    text-indent: 20px;

    /* ์ค„ ๋†’์ด */
    line-height: 1.6;

    /* ๊ธ€์ž ๊ฐ„๊ฒฉ */
    letter-spacing: 1px;

    /* ๋‹จ์–ด ๊ฐ„๊ฒฉ */
    word-spacing: 2px;

    /* ๊ทธ๋ฆผ์ž */
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

7. ๋ฐ•์Šค ๋ชจ๋ธ

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                     margin                           โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚   โ”‚               border                         โ”‚   โ”‚
โ”‚   โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚   โ”‚
โ”‚   โ”‚   โ”‚           padding                    โ”‚   โ”‚   โ”‚
โ”‚   โ”‚   โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚   โ”‚   โ”‚
โ”‚   โ”‚   โ”‚   โ”‚                             โ”‚   โ”‚   โ”‚   โ”‚
โ”‚   โ”‚   โ”‚   โ”‚         content             โ”‚   โ”‚   โ”‚   โ”‚
โ”‚   โ”‚   โ”‚   โ”‚                             โ”‚   โ”‚   โ”‚   โ”‚
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚   โ”‚   โ”‚
โ”‚   โ”‚   โ”‚                                      โ”‚   โ”‚   โ”‚
โ”‚   โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚   โ”‚
โ”‚   โ”‚                                              โ”‚   โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                                      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

content (๋‚ด์šฉ)

.box {
    width: 200px;
    height: 100px;

    /* ์ตœ์†Œ/์ตœ๋Œ€ ํฌ๊ธฐ */
    min-width: 100px;
    max-width: 500px;
    min-height: 50px;
    max-height: 300px;
}

padding (์•ˆ์ชฝ ์—ฌ๋ฐฑ)

.box {
    /* ๊ฐœ๋ณ„ ์ง€์ • */
    padding-top: 10px;
    padding-right: 20px;
    padding-bottom: 10px;
    padding-left: 20px;

    /* ๋‹จ์ถ• ์†์„ฑ */
    padding: 10px;                    /* ๋ชจ๋‘ 10px */
    padding: 10px 20px;               /* ์ƒํ•˜ 10px, ์ขŒ์šฐ 20px */
    padding: 10px 20px 15px;          /* ์ƒ 10px, ์ขŒ์šฐ 20px, ํ•˜ 15px */
    padding: 10px 20px 15px 25px;     /* ์ƒ ์šฐ ํ•˜ ์ขŒ (์‹œ๊ณ„๋ฐฉํ–ฅ) */
}

border (ํ…Œ๋‘๋ฆฌ)

.box {
    /* ๊ฐœ๋ณ„ ์ง€์ • */
    border-width: 1px;
    border-style: solid;
    border-color: black;

    /* ๋‹จ์ถ• ์†์„ฑ */
    border: 1px solid black;

    /* ๊ฐ ๋ณ€ ๊ฐœ๋ณ„ */
    border-top: 2px dashed red;
    border-right: none;
    border-bottom: 1px solid gray;
    border-left: 3px double blue;

    /* ํ…Œ๋‘๋ฆฌ ์Šคํƒ€์ผ */
    border-style: solid;    /* ์‹ค์„  */
    border-style: dashed;   /* ํŒŒ์„  */
    border-style: dotted;   /* ์ ์„  */
    border-style: double;   /* ์ด์ค‘์„  */
    border-style: none;     /* ์—†์Œ */
}

margin (๋ฐ”๊นฅ ์—ฌ๋ฐฑ)

.box {
    /* padding๊ณผ ๊ฐ™์€ ๋ฌธ๋ฒ• */
    margin: 10px;
    margin: 10px 20px;
    margin: 10px 20px 15px 25px;

    /* ๊ฐ€์šด๋ฐ ์ •๋ ฌ */
    margin: 0 auto;

    /* ์Œ์ˆ˜ ๊ฐ’ ๊ฐ€๋Šฅ */
    margin-top: -10px;
}

box-sizing

/* ๊ธฐ๋ณธ๊ฐ’: content ํฌ๊ธฐ๋งŒ ํฌํ•จ */
.box-content {
    box-sizing: content-box;
    width: 200px;
    padding: 20px;
    border: 10px solid black;
    /* ์‹ค์ œ ๋„ˆ๋น„: 200 + 40 + 20 = 260px */
}

/* border๊นŒ์ง€ ํฌํ•จ (๊ถŒ์žฅ) */
.box-border {
    box-sizing: border-box;
    width: 200px;
    padding: 20px;
    border: 10px solid black;
    /* ์‹ค์ œ ๋„ˆ๋น„: 200px (content๊ฐ€ ์ค„์–ด๋“ฆ) */
}

/* ์ „์—ญ ์„ค์ • (๊ถŒ์žฅ) */
*, *::before, *::after {
    box-sizing: border-box;
}

8. ๋ฐฐ๊ฒฝ

.box {
    /* ๋ฐฐ๊ฒฝ์ƒ‰ */
    background-color: #f0f0f0;

    /* ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€ */
    background-image: url('image.jpg');

    /* ๋ฐ˜๋ณต */
    background-repeat: repeat;      /* ๊ธฐ๋ณธ๊ฐ’ */
    background-repeat: no-repeat;
    background-repeat: repeat-x;
    background-repeat: repeat-y;

    /* ์œ„์น˜ */
    background-position: center;
    background-position: top right;
    background-position: 50% 50%;
    background-position: 10px 20px;

    /* ํฌ๊ธฐ */
    background-size: auto;          /* ์›๋ณธ ํฌ๊ธฐ */
    background-size: cover;         /* ์˜์—ญ์„ ๋ฎ์Œ */
    background-size: contain;       /* ์ด๋ฏธ์ง€ ์ „์ฒด ํ‘œ์‹œ */
    background-size: 100px 200px;

    /* ๊ณ ์ • */
    background-attachment: scroll;  /* ์Šคํฌ๋กค */
    background-attachment: fixed;   /* ๊ณ ์ • */

    /* ๋‹จ์ถ• ์†์„ฑ */
    background: #f0f0f0 url('image.jpg') no-repeat center/cover;
}

๊ทธ๋ผ๋””์–ธํŠธ

.gradient {
    /* ์„ ํ˜• ๊ทธ๋ผ๋””์–ธํŠธ */
    background: linear-gradient(to right, red, blue);
    background: linear-gradient(45deg, red, yellow, green);
    background: linear-gradient(to bottom, #fff 0%, #000 100%);

    /* ๋ฐฉ์‚ฌํ˜• ๊ทธ๋ผ๋””์–ธํŠธ */
    background: radial-gradient(circle, red, blue);
    background: radial-gradient(ellipse at center, #fff, #000);
}

9. ํ…Œ๋‘๋ฆฌ์™€ ๊ทธ๋ฆผ์ž

border-radius (๋‘ฅ๊ทผ ๋ชจ์„œ๋ฆฌ)

.box {
    border-radius: 10px;                    /* ๋ชจ๋“  ๋ชจ์„œ๋ฆฌ */
    border-radius: 10px 20px;               /* ๋Œ€๊ฐ์„  */
    border-radius: 10px 20px 30px 40px;     /* ๊ฐ ๋ชจ์„œ๋ฆฌ */
    border-radius: 50%;                     /* ์› */
}

box-shadow (๊ทธ๋ฆผ์ž)

.box {
    /* x y blur spread color */
    box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.3);

    /* ์•ˆ์ชฝ ๊ทธ๋ฆผ์ž */
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);

    /* ๋‹ค์ค‘ ๊ทธ๋ฆผ์ž */
    box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.1),
        0 4px 8px rgba(0, 0, 0, 0.1);
}

outline (์™ธ๊ณฝ์„ )

.box {
    outline: 2px solid blue;
    outline-offset: 5px;  /* border์™€์˜ ๊ฐ„๊ฒฉ */
}

/* ํฌ์ปค์Šค ์‹œ */
input:focus {
    outline: 2px solid #4CAF50;
}

10. ๋‹จ์œ„

์ ˆ๋Œ€ ๋‹จ์œ„

.box {
    width: 200px;   /* ํ”ฝ์…€ (๊ณ ์ •) */
    font-size: 12pt; /* ํฌ์ธํŠธ (์ธ์‡„์šฉ) */
}

์ƒ๋Œ€ ๋‹จ์œ„

.box {
    /* em: ๋ถ€๋ชจ ์š”์†Œ์˜ font-size ๊ธฐ์ค€ */
    font-size: 1.5em;
    padding: 2em;

    /* rem: ๋ฃจํŠธ(html) ์š”์†Œ์˜ font-size ๊ธฐ์ค€ (๊ถŒ์žฅ) */
    font-size: 1rem;    /* ๋ณดํ†ต 16px */
    margin: 1.5rem;

    /* %: ๋ถ€๋ชจ ์š”์†Œ ๊ธฐ์ค€ */
    width: 50%;
    font-size: 120%;

    /* vw/vh: ๋ทฐํฌํŠธ ๊ธฐ์ค€ */
    width: 100vw;       /* ๋ทฐํฌํŠธ ๋„ˆ๋น„์˜ 100% */
    height: 100vh;      /* ๋ทฐํฌํŠธ ๋†’์ด์˜ 100% */
    font-size: 5vw;     /* ๋ทฐํฌํŠธ ๋„ˆ๋น„์˜ 5% */
}

๋‹จ์œ„ ์„ ํƒ ๊ฐ€์ด๋“œ

์šฉ๋„ ๊ถŒ์žฅ ๋‹จ์œ„
ํฐํŠธ ํฌ๊ธฐ rem
ํŒจ๋”ฉ/๋งˆ์ง„ rem ๋˜๋Š” em
๋„ˆ๋น„ %, vw, px
๋†’์ด vh, px, auto
ํ…Œ๋‘๋ฆฌ px

11. ํ‘œ์‹œ ์†์„ฑ

display

/* ๋ธ”๋ก (ํ•œ ์ค„ ์ฐจ์ง€) */
.block {
    display: block;
}

/* ์ธ๋ผ์ธ (๋‚ด์šฉ๋งŒํผ) */
.inline {
    display: inline;
}

/* ์ธ๋ผ์ธ-๋ธ”๋ก (์ธ๋ผ์ธ์ฒ˜๋Ÿผ ๋ฐฐ์น˜, ๋ธ”๋ก์ฒ˜๋Ÿผ ํฌ๊ธฐ ์ง€์ •) */
.inline-block {
    display: inline-block;
    width: 100px;
    height: 50px;
}

/* ์ˆจ๊น€ (๊ณต๊ฐ„ ์ฐจ์ง€ ์•ˆ ํ•จ) */
.hidden {
    display: none;
}

/* Flexbox (๋‹ค์Œ ์žฅ์—์„œ ์ž์„ธํžˆ) */
.flex {
    display: flex;
}

/* Grid (๋‹ค์Œ ์žฅ์—์„œ ์ž์„ธํžˆ) */
.grid {
    display: grid;
}

visibility

/* ์ˆจ๊น€ (๊ณต๊ฐ„ ์œ ์ง€) */
.invisible {
    visibility: hidden;
}

/* ํ‘œ์‹œ */
.visible {
    visibility: visible;
}

opacity

.transparent {
    opacity: 0;     /* ์™„์ „ ํˆฌ๋ช… */
    opacity: 0.5;   /* 50% ํˆฌ๋ช… */
    opacity: 1;     /* ๋ถˆํˆฌ๋ช… */
}

12. ์šฐ์„ ์ˆœ์œ„ (Specificity)

์šฐ์„ ์ˆœ์œ„ ๊ณ„์‚ฐ

!important > ์ธ๋ผ์ธ ์Šคํƒ€์ผ > ID > Class/์†์„ฑ/๊ฐ€์ƒํด๋ž˜์Šค > ํƒœ๊ทธ/๊ฐ€์ƒ์š”์†Œ

์ ์ˆ˜ ๊ณ„์‚ฐ:
- ์ธ๋ผ์ธ ์Šคํƒ€์ผ: 1000
- ID ์„ ํƒ์ž: 100
- Class, ์†์„ฑ, ๊ฐ€์ƒํด๋ž˜์Šค: 10
- ํƒœ๊ทธ, ๊ฐ€์ƒ์š”์†Œ: 1

์˜ˆ์‹œ

/* ์ ์ˆ˜: 1 (ํƒœ๊ทธ) */
p { color: black; }

/* ์ ์ˆ˜: 10 (ํด๋ž˜์Šค) */
.text { color: blue; }

/* ์ ์ˆ˜: 100 (ID) */
#main { color: red; }

/* ์ ์ˆ˜: 11 (ํƒœ๊ทธ + ํด๋ž˜์Šค) */
p.text { color: green; }

/* ์ ์ˆ˜: 110 (ID + ํด๋ž˜์Šค) */
#main.text { color: purple; }

/* ๊ฐ•์ œ (๋น„์ถ”์ฒœ) */
p { color: orange !important; }

๊ฐ™์€ ์ ์ˆ˜์ผ ๋•Œ

๋‚˜์ค‘์— ์„ ์–ธ๋œ ์Šคํƒ€์ผ์ด ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.

.text { color: red; }
.text { color: blue; }  /* ์ด๊ฒƒ์ด ์ ์šฉ๋จ */

13. ์ƒ์†

์ƒ์†๋˜๋Š” ์†์„ฑ

body {
    /* ์ž์‹์—๊ฒŒ ์ƒ์†๋จ */
    font-family: Arial;
    font-size: 16px;
    color: #333;
    line-height: 1.6;
}

์ƒ์†๋˜์ง€ ์•Š๋Š” ์†์„ฑ

.parent {
    /* ์ž์‹์—๊ฒŒ ์ƒ์† ์•ˆ ๋จ */
    width: 500px;
    height: 300px;
    border: 1px solid black;
    background: gray;
    margin: 20px;
    padding: 10px;
}

์ƒ์† ์ œ์–ด

.child {
    color: inherit;     /* ๋ถ€๋ชจ ๊ฐ’ ์ƒ์† */
    border: initial;    /* ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ */
    margin: unset;      /* ์ƒ์†๋˜๋ฉด inherit, ์•„๋‹ˆ๋ฉด initial */
}

14. CSS ๋ฆฌ์…‹

๋ธŒ๋ผ์šฐ์ €๋งˆ๋‹ค ๊ธฐ๋ณธ ์Šคํƒ€์ผ์ด ๋‹ฌ๋ผ์„œ ์ดˆ๊ธฐํ™”๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

๊ฐ„๋‹จํ•œ ๋ฆฌ์…‹

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI',
                 Roboto, 'Noto Sans KR', sans-serif;
    line-height: 1.6;
}

ul, ol {
    list-style: none;
}

a {
    text-decoration: none;
    color: inherit;
}

img {
    max-width: 100%;
    display: block;
}

button {
    cursor: pointer;
    border: none;
    background: none;
}

15. ์™„์ „ํ•œ ์˜ˆ์ œ

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS ๊ธฐ์ดˆ ์˜ˆ์ œ</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <header class="header">
        <h1 class="logo">My Website</h1>
        <nav class="nav">
            <a href="#" class="nav-link">ํ™ˆ</a>
            <a href="#" class="nav-link">์†Œ๊ฐœ</a>
            <a href="#" class="nav-link">์—ฐ๋ฝ์ฒ˜</a>
        </nav>
    </header>

    <main class="main">
        <article class="card">
            <h2 class="card-title">์ œ๋ชฉ์ž…๋‹ˆ๋‹ค</h2>
            <p class="card-text">
                Lorem ipsum dolor sit amet, consectetur adipiscing elit.
            </p>
            <button class="btn">์ž์„ธํžˆ ๋ณด๊ธฐ</button>
        </article>
    </main>
</body>
</html>
/* style.css */

/* ๋ฆฌ์…‹ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Sans KR', sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

/* ํ—ค๋” */
.header {
    background-color: #2c3e50;
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: bold;
}

.nav-link {
    color: white;
    text-decoration: none;
    margin-left: 1.5rem;
    transition: opacity 0.3s;
}

.nav-link:hover {
    opacity: 0.7;
}

/* ๋ฉ”์ธ */
.main {
    max-width: 800px;
    margin: 2rem auto;
    padding: 0 1rem;
}

/* ์นด๋“œ */
.card {
    background: white;
    border-radius: 8px;
    padding: 2rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.card-title {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: #2c3e50;
}

.card-text {
    color: #666;
    margin-bottom: 1.5rem;
}

/* ๋ฒ„ํŠผ */
.btn {
    background-color: #3498db;
    color: white;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s;
}

.btn:hover {
    background-color: #2980b9;
}

16. ์š”์•ฝ

๊ฐœ๋… ์„ค๋ช…
์„ ํƒ์ž ์Šคํƒ€์ผ์„ ์ ์šฉํ•  ์š”์†Œ ์ง€์ •
๋ฐ•์Šค ๋ชจ๋ธ content, padding, border, margin
๋‹จ์œ„ px, rem, em, %, vw, vh
์šฐ์„ ์ˆœ์œ„ !important > inline > ID > class > ํƒœ๊ทธ
์ƒ์† ํ…์ŠคํŠธ ๊ด€๋ จ ์†์„ฑ์€ ์ƒ์†๋จ

17. ์—ฐ์Šต ๋ฌธ์ œ

์—ฐ์Šต 1: ๋ฒ„ํŠผ ์Šคํƒ€์ผ๋ง

๋‹ค์–‘ํ•œ ์ƒ‰์ƒ์˜ ๋ฒ„ํŠผ์„ ๋งŒ๋“ค์–ด๋ณด์„ธ์š”. - primary, secondary, danger, success

์—ฐ์Šต 2: ์นด๋“œ ์ปดํฌ๋„ŒํŠธ

์ด๋ฏธ์ง€, ์ œ๋ชฉ, ์„ค๋ช…, ๋ฒ„ํŠผ์ด ์žˆ๋Š” ์นด๋“œ๋ฅผ ๋งŒ๋“œ์„ธ์š”.

์—ฐ์Šต 3: ๋„ค๋น„๊ฒŒ์ด์…˜ ๋ฐ”

๊ฐ€๋กœ ๋ฉ”๋‰ด๋ฅผ ๋งŒ๋“ค๊ณ  hover ํšจ๊ณผ๋ฅผ ์ถ”๊ฐ€ํ•˜์„ธ์š”.


๋‹ค์Œ ๋‹จ๊ณ„

04_CSS_Layout.md์—์„œ Flexbox์™€ Grid๋ฅผ ๋ฐฐ์›Œ๋ด…์‹œ๋‹ค!

to navigate between lessons