๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

์˜ค์ฆˆ์ฝ”๋”ฉ์Šค์ฟจ ํ”„๋ก ํŠธ์—”๋“œ 10๊ธฐ/๋ฒ ์ด์Šค์บ ํ”„

๋น„๊ธฐ๋„ˆ ํŠธ๋ž™ 8 - CSS ์ด๋ก  (1)

๋‚ด์šฉ ์š”์•ฝ

 

CSS(Cascading Style Sheets) : HTML, XML๊ฐ™์€ ๋งˆํฌ์—… ์–ธ์–ด ๋ฌธ์„œ์˜ ์Šคํƒ€์ผ์„ ๊พธ๋ฏธ๊ธฐ ์œ„ํ•œ ์Šคํƒ€์ผ ์‹œํŠธ ์–ธ์–ด

CSS ์†์„ฑ ํ•™์Šต ์‚ฌ์ดํŠธ : w3schools

 

 

  • css ์ •์˜ํ•˜๊ธฐ

1. ์ธ๋ผ์ธ ์Šคํƒ€์ผ : <style> ์š”์†Œ ๋‚ด๋ถ€์— css ์†์„ฑ์„ ์ง์ ‘ ์ž…๋ ฅํ•˜๋Š” ๋ฐฉ์‹

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS ์ด๋ก ํ•™์Šต</title>
    <style>
        body {
            margin : 0;
            padding : 20px;
            font-family: Arial, sans-serif;
        }
        h1 {
            background-color : black;
            color : #fff;
        }
        h1, h2 {
            text-align: center;
        }
        a {
            text-decoration: none;
            color:unset;
        }
    </style>
</head>

 

2. ์™ธ๋ถ€ css ํŒŒ์ผ (๊ถŒ์žฅ) : <link> ์š”์†Œ์— href ์†์„ฑ์œผ๋กœ css ํŒŒ์ผ๋ช…์„ ์ž…๋ ฅํ•˜๋Š” ๋ฐฉ์‹

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS ์ด๋ก ํ•™์Šต</title>
    <!-- rel ์†์„ฑ์€ ํ˜„์žฌ ๋ฌธ์„œ์™€ ์™ธ๋ถ€ ๋ฆฌ์†Œ์Šค ์‚ฌ์ด์˜ ์—ฐ๊ด€ ๊ด€๊ณ„๋ฅผ ์˜๋ฏธ -->
    <!-- href ์†์„ฑ์€ ๋งํฌ -->
    <link rel="stylesheet" href="style.css">
</head>

 

style.css

@charset "UTF-8";

body {
    margin : 0;
    padding : 20px;
    font-family: Arial, sans-serif;
}
h1 {
    background-color : black;
    color : #fff;
}
h1, h2 {
    text-align: center;
}
a {
    text-decoration: none;
    color:unset;
}

 

 

  • ์„ ํƒ์ž

css๋Š” html ์š”์†Œ๋ฅผ ์„ ํƒํ•˜๊ธฐ ์œ„ํ•ด ์„ ํƒ์ž๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

body {
    margin : 0; /* ํ…Œ๋‘๋ฆฌ ๋ฐ– ์—ฌ๋ฐฑ ํฌ๊ธฐ ์„ค์ • */
    padding : 20px; /* ํ…Œ๋‘๋ฆฌ ์•ˆ ์—ฌ๋ฐฑ ํฌ๊ธฐ ์„ค์ • */
    font-family : Arial, sans-serif; /* ํฐํŠธ ์ข…๋ฅ˜ ์„ค์ • */
}
h1 {
    background-color : black; /* h1 ํƒœ๊ทธ ์˜์—ญ์˜ ๋ฐฐ๊ฒฝ ์ƒ‰ ์„ค์ • */
    color : #fff; /* ๊ธ€์ž ์ƒ‰ ์„ค์ • */
}
h1, h2 {
    text-align : center; /* ํ…์ŠคํŠธ์˜ ์ •๋ ฌ ์„ค์ • (์ค‘์•™) */
}
a {
    text-decoration : none; /* ํ…์ŠคํŠธ๋ฅผ ๊พธ๋ฏธ๋Š” ์š”์†Œ(๋ฐ‘์ค„ ๋“ฑ) ์„ค์ • */
    color : unset; 
}

 

์Šคํƒ€์ผ์„ ์ง€์ •ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์†์„ฑ๊ณผ ๊ฐ’์˜ ์Œ์„ ์‚ฌ์šฉํ•œ๋‹ค.

ex) background-color ์†์„ฑ - black ๊ฐ’

 

body๋Š” <body> ์š”์†Œ, h1๋Š” <h1>์š”์†Œ, a๋Š” <a>์š”์†Œ, h1, h2์˜ ๊ฒฝ์šฐ์—๋Š” <h1>์š”์†Œ์™€ <h2>์š”์†Œ ๋‘˜ ๋ชจ๋‘ ์„ ํƒํ•  ์ˆ˜ ์žˆ๋‹ค.

์ด ์™ธ์—๋„ id, class ์„ ํƒ์ž๋กœ ๊ฐ๊ฐ์˜ ์Šคํƒ€์ผ์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

1. class ์„ ํƒ์ž

์—ฌ๋Ÿฌ ์š”์†Œ๋ฅผ ๊ทธ๋ฃนํ™”ํ•˜๊ณ , ํ•ด๋‹น ๊ทธ๋ฃน์— ์Šคํƒ€์ผ์„ ์ ์šฉํ•œ๋‹ค.

ํ•˜๋‚˜์˜ ์š”์†Œ๊ฐ€ ์—ฌ๋Ÿฌ ํด๋ž˜์Šค๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๊ณ , ์—ฌ๋Ÿฌ ์š”์†Œ๊ฐ€ ๋™์ผํ•œ ํด๋ž˜์Šค๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋‹ค.

 

beginner.html

    <ul class="highlight paragraph">
        <li>a. HTML ์˜ˆ์Šตํ•˜๊ธฐ</li>
        <li>b. MDN ์‚ฌ์ดํŠธ ์ ‘์†ํ•˜๊ธฐ</li>
        <li>c. w3school ์‚ฌ์ดํŠธ ์ ‘์†ํ•˜๊ธฐ</li>
        <li>d. ์‹ค์Šต ๋„์ „ํ•˜๊ธฐ</li>
    </ul>
    <h2 class="highlight">๊ธ€์”จ ๊ฐ•์กฐํ•˜๊ธฐ</h2>
    <p><i>HTML</i> ์˜ˆ์Šตํ•˜๊ธฐ</p>
    <p><b>MDN</b> ์‚ฌ์ดํŠธ ์ ‘์†ํ•˜๊ธฐ</p>
    <p><u>w3school</u> ์‚ฌ์ดํŠธ ์ ‘์†ํ•˜๊ธฐ</p>
    <p><em>์‹ค์Šต</em>๋„์ „ํ•˜๊ธฐ</p>

 

style.css

.highlight {
    background-color: yellow;
}

.paragraph {
    font-size : 12px;
}

 

 

2. id ์„ ํƒ์ž

id ์„ ํƒ์ž๋Š” ์œ ์ผ์„ฑ์„ ๋ณด์žฅํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•œ๋‹ค.

๋•Œ๋ฌธ์— html ๋ฌธ์„œ ์ „์ฒด์—์„œ ๋™์ผํ•œ id๋ฅผ ๊ฐ€์ง€๋Š” ์š”์†Œ๊ฐ€ ๋‘ ๊ฐœ ์ด์ƒ ์žˆ์œผ๋ฉด ์•ˆ๋œ๋‹ค. 

    <div id="header">
        <div class="menu">์˜ค๋Š˜ ํ• ์ผ</div>
        <div class="menu">๋‚ด์ผ ํ• ์ผ</div>
        <div class="menu">๋ชจ๋ ˆ ํ• ์ผ</div>
    </div>

 

#header {
    padding : 0;
    margin : 0;
    background-color: aquamarine;
    display : flex;
    justify-content: space-between;
}

#header .menu {
    padding : 10px 15px;
    list-style-type: none;
}

 

 

 

์‹ค์Šต ๊ณผ์ œ

 

@charset "UTF-8";

body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
}

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

.daily-title {
    color : #3498db;
}

.task {
    font-size : 18px;
    margin-bottom: 10px;
}

#challenge-task {
    font-weight : bold;
}