ํ’€์Šคํƒ ์›น๐ŸŒ ๊ฐœ๋ฐœ์ž ์ง€๋ง์ƒ ๐Ÿง‘๐Ÿฝโ€๐Ÿ’ป
โž• ์ธ๊ณต์ง€๋Šฅ ๊ด€์‹ฌ ๐Ÿค–


Categories


Recent views

  • 1
  • 2
  • 3
  • 4
  • 5

CSS ๊ฐœ๋…

CSS

CSS์˜ ๊ฐœ๋…๊ณผ ๊ธฐ๋ณธ ์‚ฌ์šฉ๋ฒ•

HTML => ์ •๋ณด์™€ ๊ตฌ์กฐํ™”
CSS => styling์˜ ์ •์˜

์ด ๋‘˜์€ ๊ฐ์ž ๋ฌธ๋ฒ•์ด ๋‹ค๋ฅธ ๋ณ„๊ฐœ์˜ ์–ธ์–ด, ํ•˜์ง€๋งŒ HTML์ด ์—†์œผ๋ฉด CSS๋Š” ๋ฌด์˜๋ฏธ

h1 { 
	color:blue;
	font-size:15px; 
}

  • h1 : ์…€๋ ‰ํ„ฐ(selector),
  • color:blue; : ์„ ์–ธ
    • color: ํ”„๋กœํผํ‹ฐ(property), blue: ๊ฐ’(value)
  • ์„ธ๋ฏธ์ฝœ๋ก (;)์œผ๋กœ ๊ฐ๊ฐ์˜ ๊ฐ’์„ ๊ตฌ๋ถ„
  • CSS์˜ ์ฃผ์„ ์„ค์ •์€ /* ๋‚ด์šฉ */

CSS ํ™œ์šฉ

CSS ํ™œ์šฉํ•˜๊ธฐ 1. Inline(์ธ๋ผ์ธ)

๐Ÿงพ๏ธ 00_intro.html ๋ฐ”๋”” ๋ถ€๋ถ„
<body>
    <h1 style="color:red;">CSS intro</h1>
</body>
  • html ํƒœ๊ทธ ์•ˆ์— ์ธ๋ผ์ธ์œผ๋กœ CSS๋ฅผ ์ ์šฉํ•ด๋ณธ ๊ฒƒ, ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ํž˜๋“œ๋ฏ€๋กœ ๊ธˆ์ง€๋œ๋‹ค.

CSS ํ™œ์šฉํ•˜๊ธฐ 2. CSS ๋‚˜๋ˆ„๊ธฐ

๐Ÿงพ๏ธ 00_intro.html ํŒŒ์ผ ํ—ค๋”์™€ ๋ฐ”๋”” ๋ถ€๋ถ„
<head>
    <style> 
    h2{ <!--๋ณดํ†ต ์—ฌ๋Ÿฌ๊ฐ’์ด ๋‚˜์˜ค๋ฏ€๋กœ CSS ์‚ฌ์šฉ์‹œ ์—ฌ๋Ÿฌ์ค„๋กœ ๋‚˜๋ˆ”-->
        color: blue;
        font-size:50px;
    }
    </style>
</head>
<body>
    <h2>CSS is awesome</h2>
</body>

CSS ํ™œ์šฉํ•˜๊ธฐ 3.ํŒŒ์ผ ๋ถ„๋ฆฌํ•˜๊ธฐ

๐Ÿงพ๏ธ ๊ฐ™์€ ํด๋” ๋‚ด์˜ 00__intro css ํŒŒ์ผ
p{
    color: green;
}
๐Ÿงพ๏ธ 00_intro.html ํŒŒ์ผ ํ—ค๋”์™€ ๋ฐ”๋”” ๋ถ€๋ถ„
<head>
    <link rel="stylesheet" href="00_intro css">
</head>
<body>
    <p>Lorem ipsum dolor sit amet.</p>
</body>
</html>
๐Ÿ’ก vscode ๊ธฐ๋Šฅ

lorem ipsum ๊ธฐ๋Šฅ: ๋žœ๋ค์˜ ์˜๋ฏธ์—†๋Š” ๋ฌธ์žฅ ๋งŒ๋“ค์–ด์คŒ

lorem{๋‹จ์–ด์ˆ˜}

๊ฐ’

๊ฐ’ : ํ‚ค์›Œ๋“œ, ํฌ๊ธฐ ๋‹จ์œ„, ์ƒ‰๊น” ๋“ฑ์ด ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ์Œ

  • ํ‚ค์›Œ๋“œ ์˜ˆ์‹œ : display: block, visiblity: hidden ๋“ฑโ€ฆ

ํ‚ค์›Œ๋“œ์˜ ๊ฒฝ์šฐ ๊ฐœ๋ฐœ์ž ๋„๊ตฌ๋กœ ํ™•์ธ ๊ฐ€๋Šฅ

  • ์ฃผํ™ฉ์ƒ‰ ์˜์—ญ : ์„ค์ •๋œ ํฌ๊ธฐ ์˜์—ญ
  • ํŒŒ๋ž€์ƒ‰ ์˜์—ญ : ์‹ค์ œ๋กœ ํ•ด๋‹น ์š”์†Œ๊ฐ€ ์ฐจ์ง€ํ•˜๊ณ  ์žˆ๋Š” ๋ถ€๋ถ„
๐Ÿงพ๏ธ CSS ๊ฐ’ ์„ค์ • ์˜ˆ์‹œ (01_css_val css ํŒŒ์ผ)
/* CSS ์ฃผ์„ #์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” ๊ฒƒ์€ ์•„์ด๋””์ด๋‹ค.*/
#hello {
    font-size: 50px;
}
#welcome{
    font-size: 50%; /* ๊ธฐ์กด์˜ ํฌ๊ธฐ ๋Œ€๋น„ํ•ด์„œ ๋ฐ”๊ฟˆ*/
}
#lunch{
    font-size: 5em; /* ๊ธฐ๋ณธ์„ค์ •์˜ x๋ฐฐ ์ปค์ง€๊ฒŒ ํ•จ  %์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๊ณฑ์…ˆ๋จ*/
}
/*div๋Š” ๋ถ€๋ชจ*/
div{
    width: 50%;
}
/*h1์€ ์ž์‹, ๋ถ€๋ชจ์˜ width๋ฅผ ์ƒ์†๋ฐ›์•„์„œ ๊ฒฐ๊ตญ์€ 0.5 * 0.5 ์˜ ๊ฐ’์„ ๊ฐ–๋Š”๋‹ค.*/
h1{
    width: 50%;
}
#snack {
    font-size: 0.5rem;
}
#menu { /*ํ™”๋ฉด ํฌ๊ธฐ์— ์ƒ๋Œ€์ ์œผ๋กœ ํฌ๊ธฐ๊ฐ€ ๋ฐ”๋€Œ๋Š” ๋ฐ˜์‘ํ˜• ๋‹จ์œ„*/
    background-color: red;
    width: 50vw;
    height: 50vh;
    /*ํ”„๋กœํผํ‹ฐ๊ฐ’ ์•ž์— ์ฝœ๋ก ์„ ๋ถ™์ด๊ณ  ํ•œ์นธ ๋„์šฐ๋Š”๊ฒŒ ๊ตญ๋ฃฐ*/
}
๐Ÿงพ๏ธ CSS ๊ฐ’ ์„ค์ • ์˜ˆ์‹œ (01_css_val.html ํŒŒ์ผ)
<link rel="stylesheet" href="01_css_val css">
</head>
<body>
    <P id="hello">์•ˆ๋‡ฝ</P><!--px ๋‹จ์œ„-->
    <P id="welcome">๋ฐ˜๊ฐ‘์Šต๋‹ˆ๋‹ค</P> <!--% ๋‹จ์œ„-->
    <h1>
        <P id="lunch">์ ์‹ฌ์‹œ๊ฐ„์ž…๋‹ˆ๋‹ค.</P><!--em ๋‹จ์œ„-->
    </h1>
    <h1>
        <p id="snack">์˜ค๋Š˜ ๊ฐ„์‹์€ ๋„์‹œ๋ฝ</p><!--rem ๋‹จ์œ„-->
    </h1>
    <div>
        <h1>๋ฐฐ๊ณ ํŒŒ </h1>
    </div>
    <h1 id="menu">์˜ค๋Š˜์˜ ๋ฉ”๋‰ด</h1><!--viewport ๋‹จ์œ„-->
</body>

px

  • ํ•œ ํ”ฝ์…€์€ RGB๋กœ ์ƒ‰์„ ๊ตฌ๋ถ„ํ•˜์—ฌ ํ‘œํ˜„ํ•˜๋ฉฐ, ๋งค์šฐ ์ž‘์€ ์‚ฌ๊ฐํ˜•
  • ๋””๋ฐ”์ด์Šค๋ณ„๋กœ ํ”ฝ์…€์˜ ํฌ๊ธฐ๋Š” ์ œ๊ฐ๊ฐ, ๋Œ€๋ถ€๋ถ„ ๋ธŒ๋ผ์šฐ์ €๋Š” 1px๋ฅผ 1/96์ธ์น˜๋กœ ์ง€์ •

%

๋ฐฑ๋ถ„์œจ ๋‹จ์œ„์˜ ์ƒ๋Œ€ ๋‹จ์œ„์ด๋‹ค.
์š”์†Œ์— ์ง€์ •๋œ ์‚ฌ์ด์ฆˆ(์ƒ์†๋œ ์‚ฌ์ด์ฆˆ๋‚˜ ๋””ํดํŠธ ์‚ฌ์ด์ฆˆ)์— ์ƒ๋Œ€์ ์ธ ์‚ฌ์ด์ฆˆ๋ฅผ ์„ค์ •ํ•œ๋‹ค.
๋ถ€๋ชจ์™€ ์ƒ์†, ์ฆ‰ ๊ณฑ์…ˆ ๋จ

em

em์€ ๋ฐฐ์ˆ˜ ๋‹จ์œ„๋กœ ์ƒ๋Œ€ ๋‹จ์œ„์ด๋‹ค. ์š”์†Œ์— ์ง€์ •๋œ ์‚ฌ์ด์ฆˆ์— ์ƒ๋Œ€์ ์ธ ์‚ฌ์ด์ฆˆ๋ฅผ ์„ค์ •ํ•œ๋‹ค. %์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๊ณฑ์…ˆ, ์ฆ‰ ์ƒ์†๋จ

rem

em๊ณผ ๋น„์Šทํ•˜๋‚˜ ์ƒ๋Œ€ ๋‹จ์œ„๊ฐ€ ์•„๋‹Œ, ์ ˆ๋Œ€ ๋‹จ์œ„, ์ฆ‰ 2๋ฐฐ๋กœ ์„ค์ •ํ•˜๋ฉด ๋‹ค๋ฅธ ๊ฐ’์„ ๋‹ค ๊ณฑํ•ด๋„ 2๋ฐฐ๋กœ ์„ค์ •๋จ

  • ๋ณดํ†ต 1rem์€ 16px

viewport ๋‹จ์œ„

๋””๋ฐ”์ด์Šค๋งˆ๋‹ค ๋‹ค๋ฅธ ํฌ๊ธฐ์˜ ํ™”๋ฉด์„ ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ƒ๋Œ€์ ์ธ ๋‹จ์œ„์ธ viewport๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ‘œํ˜„ํ•˜๋Š” ๋‹จ์œ„, ์ธํ„ฐ๋„ท์ฐฝ์ด๋‚˜ ๋ชจ๋‹ˆํ„ฐํฌ๊ธฐ๋ฅผ ๋ฐ”๊พธ๋ฉด ๋™์ ์œผ๋กœ ๋ฐ”๋€๋‹ค. ๋ฐ˜์‘ํ˜• ๋‹จ์œ„
IE 8 ์ดํ•˜๋Š” ์ง€์›ํ•˜์ง€ ์•Š์œผ๋ฉฐ IE 9~11, Edge๋Š” ์ง€์›์ด ์™„์ „ํ•˜์ง€ ์•Š๋‹ค

์ƒ‰์ƒ ํ‘œํ˜„ ๋‹จ์œ„

HEX ํ‘œํ˜„: 16์ง„์ˆ˜์˜ ๋‘์ž๋ฆฌ์”ฉ RGB ํ‘œํ˜„ \#24f4cd, \#ffffff(ํฐ์ƒ‰)
RGB ํ‘œํ˜„: ๋นจ๊ฐ•, ์ดˆ๋ก, ํŒŒ๋ž‘์ด ์„ž์ด๋Š” ์ •๋„๋ฅผ ํ‘œํ˜„ (0~255)
RGBA ํ‘œํ˜„: RGB + ํˆฌ๋ช…๋„ (alpha)

Box model

margin : ๋‚ด์šฉ๊ณผ ๋‚ด์šฉ์‚ฌ์ด์˜ ์—ฌ๋ฐฑ
border: ํ…Œ๋‘๋ฆฌ ์˜์—ญ
padding: ํ…Œ๋‘๋ฆฌ ์•ˆ์ชฝ์˜ ๋‚ด๋ถ€ ์—ฌ๋ฐฑ, ์š”์†Œ์— ์ ์šฉ๋œ ์š”์†Œ๋“ค์ด ๋‚ด์šฉ๊ณผ ํ•จ๊ป˜ ์ ์šฉ๋จ
contents: ๋‚ด์šฉ, ์—ญ์‹œ ์Šคํƒ€์ผ ์ ์šฉ๋จ

๐Ÿงพ๏ธ Box model ์˜ˆ์‹œ(02_box.html)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="02_box css">
</head>
<body>
    <div class="margin border"></div>
    <div class="margin padding"></div>
    <div class="margin border"></div>
    <div class="margin"></div>
    <div class="margin padding"></div>
    <div class="margin-1"></div>
    <div class="margin-2"></div>
    <div class="margin-3"></div>
    <div class="margin-4"></div>
</body>
</html>
๐Ÿงพ๏ธ Box model ์˜ˆ์‹œ CSS (02_box css)
div{
    width: 100px;
    height: 100px;
    background-color: rgb(196, 61, 61);
}

.margin {
    margin-top: 10px;
    margin-bottom: 10px;
    margin-left: 10px;
    margin-right: 10px;
}
.padding{
    padding-top: 20px;
    padding-bottom: 10px;
}
.border{
    /* border-width: 2px;
    border-color: blue;
    border-style: dotted; */
    border: 3px blue dotted; /*์œ„์˜ ์ถ•์•ฝํ˜•*/
}
.margin-1{
    margin: 10px; 
    /* ์ƒํ•˜ ์ขŒ์šฐ ์ „๋ถ€ ๋งˆ์ง„ 10 */
}
.margin-2{
    margin: 10px 20px;
    /* ์œ„ ์•„๋ž˜ ๋งˆ์ง„ 10px, 20px */
}
.margin-3{
    margin: 10px 20px 30px;
    /*์œ„ 10 ์–‘์˜† 20 ์•„๋ž˜ 30px ๋งˆ์ง„ ์ƒ๊น€*/
}
.margin-4{
    margin: 10px 20px 30px 40px;
    /* ์œ„ ๋งˆ์ง„ ๋ถ€ํ„ฐ ์‹œ๊ณ„๋ฐฉํ–ฅ์œผ๋กœ 10, 20, 30, 40 px ๋งˆ์ง„ ์ƒ๊น€ */
}
/*border, padding์—๋„ ์ ์šฉ๋จ*/

margin

  • id ์†์„ฑ
    ํŠน์ • id ์†์„ฑ์„ ๊ฐ€์ง„ ํƒœ๊ทธ ํ•˜๋‚˜์—๋งŒ ์ ์šฉํ• ๋•Œ ์“ฐ๋Š” ์†์„ฑ, CSS์—์„œ ์•ž์— #์„ ๋ถ™์—ฌ ํ‘œํ˜„

  • class ์†์„ฑ
    ๊ฐ™์€ ํด๋ž˜์Šค ์†์„ฑ์˜ ํƒœ๊ทธ๋ฅผ ์ „๋ถ€ ์ ์šฉํ• ๋•Œ ์“ฐ๋Š” ์†์„ฑ, CSS์—์„œ ์•ž์— .(์ )์„ ๋ถ™์—ฌ ํ‘œํ˜„
    • ๊ฐ๊ธฐ ๋‹ค๋ฅธ class๋ฅผ ํ•œ ํƒœ๊ทธ์— ์ŠคํŽ˜์ด์Šค๋ฐ”(๊ณต๋ฐฑ)์œผ๋กœ ๋‚˜๋ˆ„์–ด ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ๋งˆ์ง„ ์ƒ์‡„ํ˜„์ƒ: ๋‹ค๋ฅธ ์กด์žฌ์˜ ๋งˆ์ง„๊ณผ ์ƒ์‡„๋จ

    padding

border

shorthand

Display

display ํ”„๋กœํผํ‹ฐ๋ฅผ ์ด์šฉํ•ด block๊ณผ inline ๊ทธ๋ฆฌ๊ณ  inline-block, none์„ ์ •ํ•ด์ค„ ์ˆ˜ ์žˆ๋‹ค. ์›๋ž˜ ๊ธฐ๋ณธ์ด block์ด์—ฌ๋„ inline์œผ๋กœ ๋ฐ”๊ฟ€ ์ˆ˜ ์ž‡์Œ

๐Ÿงพ๏ธ 03_display css ํŒŒ์ผ ์˜ˆ์‹œ
div {
    background-color: cornflowerblue;
    margin-left: auto;
    margin-right: auto;
}

.half {
    width: 50%;
}

.b {
    display: block;
}

.i {
    display: inline;
}

.bi {
    display: inline-block;
    margin-top: 20px;
}

.bg {
    background-image: url(https://picsum.photos/200/300);
}
.text {
    font-family: 'Saira Stencil One', cursive;
}
๐Ÿงพ๏ธ Display ์˜ˆ์‹œ (03_display.html)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link href="https://fonts.googleapis.com/css?family=Fira+Code|Saira+Stencil+One&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="03_display.css">
</head>
<body>
    <div>
        <h1>div๋Š” block์ž…๋‹ˆ๋‹ค.</h1>
    </div>
    <div class="half i">
        <span>test</span> <!-- <h1>์—ฌ๊ธฐ๋Š” ์ ˆ๋ฐ˜๋งŒ!</h1> -->
    </div>
    <!-- <h1>์—ฌ๊ธฐ๋Š” h1์ž…๋‹ˆ๋‹ค.</h1> -->
    <div class="half i">
        <span>test</span> <!-- <h1>์—ฌ๊ธฐ๋Š” ์ ˆ๋ฐ˜๋งŒ!</h1> -->
    </div>

    <span class="bi">์—ฌ๊ธฐ๋Š” span</span>
    <input class="b" type="text">
    <input type="date">
    <h1 class="bg">hello.</h1>
    <h1 class="text">ooh yeah.</h1>
</body>
</html>

block

  • ํ•ญ์ƒ ์ƒˆ๋กœ์šด ๋ผ์ธ์—์„œ ์‹œ์ž‘ํ•œ๋‹ค.
  • ๋„ˆ๋น„๊ฐ€ ์ •ํ•ด์ง€๋ฉด ๋งˆ์ง„์œผ๋กœ ๋‚˜๋จธ์ง€ ์˜์—ญ์„ ์ฑ„์›€(margin-right: auto;(๊ธฐ๋ณธ๊ฐ’)) margin-left: auto; ๋„ ๊ฐ™์ด ํ•˜๋ฉด ์ค‘์•™ ์ •๋ ฌ์ด ๋จ
  • ํ™”๋ฉด ํฌ๊ธฐ ์ „์ฒด์˜ ๊ฐ€๋กœํญ์„ ์ฐจ์ง€ํ•œ๋‹ค(width: 100%)
  • block ๋ ˆ๋ฒจ ์š”์†Œ ๋‚ด์— inline
  • block ๋ ˆ๋ฒจ ์š”์†Œ์˜ ์˜ˆ

    inline

  • span, input ๋“ฑ
  • ์ƒˆ๋กœ์šด ๋ผ์ธ์—์„œ ์‹œ์ž‘ํ•˜์ง€ ์•Š์œผ๋ฉฐ ๋ฌธ์žฅ์˜ ์ค‘๊ฐ„์— ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ๋”ฐ.
  • content์˜ ๋„ˆ๋น„๋งŒํผ ๊ฐ€๋กœํญ์„ ์ฐจ์ง€ํ•œ๋‹ค.
  • width, height, margin-top, margin-bottom ๊ฐ™์€ ํ”„๋กœํผํ‹ฐ๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์—†๋‹ค.
  • ์ƒ, ํ•˜ ์—ฌ๋ฐฑ์€ line-height๋กœ ์ง€์ •ํ•œ๋‹ค.

inline-block

  • ๋‘ ์š”์†Œ๋ฅผ ๋ชจ๋‘ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์„ฑ์งˆ, ๋งˆ์ง„์„ ์ค„ ์ˆ˜๋„ ์žˆ์Œ
  • inline ๋ ˆ๋ฒจ ์š”์†Œ์ฒ˜๋Ÿผ ํ•œ์ค„์— ํ‘œ์‹œ๋˜๋ฉด์„œ ๋งˆ์ง ์†์„ฑ์„ ๋ชจ๋‘ ์ •ํ•ด์ค„ ์ˆ˜ ์žˆ๋‹ค.

    none

  • ์ ์šฉํ•˜๋ฉด ๋ณด์ด์ง€์•Š์Œ, ๋™์ ์œผ๋กœ ์›น์„ ๋งŒ๋“ค์–ด ์‚ฌ๋ผ์ง€๊ฒŒ ๋งŒ๋“ค๊ณ  ์‹ถ์„๋•Œ ์”€ (๊ณต๊ฐ„์กฐ์ฐจ ์‚ฌ๋ผ์ง0)

visibility ์†์„ฑ

visible

  • ๋ณด์ด๊ฒŒ ํ•œ๋‹ค

    hidden

  • ์•ˆ๋ณด์ด๊ฒŒ ํ•œ๋‹ค, none๊ณผ ๋‹ฌ๋ฆฌ ์‚ฌ๋ผ์ง€์ง„ ์•Š๊ณ  ๋ณด์ด์ง€๋งŒ ์•Š๋Š”๋‹ค. ์˜์—ญ์„ ๊ทธ๋Œ€๋กœ ์ฐจ์ง€ํ•˜๊ณ  ์žˆ์Œ

background-image ์†์„ฑ

  • url(https://picsum.photos/200/300);์„ ์ง€์ •ํ•˜๋ฉด ๊ทธ ๊ณต๊ฐ„๋งŒํผ์˜ ์‚ฌ์ง„์„ ๋ณด์—ฌ์คŒ

font-size, font-family, letter-spacing, white space, text-align ๋“ฑ์ด ์žˆ์Œ

position ์†์„ฑ

  • left: , right: , bottom, top ์š”์†Œ๋กœ ์–ผ๋งˆ๋‚˜ ๋–จ์–ด์ ธ์•ผ ํ•˜๋Š” ๊ฐ€๋ฅผ ํฌ๊ธฐ๋กœ ์ •ํ•ด์คŒ
  • ์ฆ‰ ์–ผ๋งˆ๋‚˜ ๋–จ์–ด์ ธ์•ผํ•˜๋Š”๊ฐ€ ex) left: 50px == ์™ผ์ชฝ์œผ๋กœ ๋ถ€ํ„ฐ 50px ๋–จ์–ด์ง
  • ๋งŒ์•ฝ left: 0px, right: 0px ์ฒ˜๋Ÿผ ์„œ๋กœ ์ถฉ๋Œํ•˜๋ฉด ์™ผ์ชฝ, ๊ทธ๋ฆฌ๊ณ  ์œ„์ชฝ์ด ์šฐ์„ ๋จ
  • ๊ฐ div์˜ ์ค‘์‹ฌ์€ div๊ฐ€ ๊ทธ ํ•ด๋‹น ๋ชจ์„œ๋ฆฌ์—์„œ ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ์ชฝ์œผ๋กœ ๊ฒฐ์ •๋˜๋Š”๋“ฏ?
  • Ctrl + enter๋กœ ์ฝ”๋“œ ์ค‘๊ฐ„์— ์ค„๋ฐ”๊ฟˆ ๊ฐ€๋Šฅ
๐Ÿงพ๏ธ Position ์†์„ฑ ์˜ˆ์‹œ (04_postion css)
div {
    height: 100px;
    width: 100px;
}

.blue {
    background-color: blue;
    position: static;
}
.red {
    background-color: red;
    position: relative;
    left: 50px;
    bottom: 50px;
}
.green {
    background-color: green;
    position: absolute;    
    left: 0px; 
    bottom: 0px;
}
.yellow {
    background-color: yellow;
    position: fixed;
    right: 0px;
    top: 0px;
}

.parent {   
    height: 200px;
    width: 100%;
    background-color: gray;
    position: relative;
}

.children {
    background-color: pink;
    position: absolute;
    left: 0px;
    bottom: 0px;
}
๐Ÿงพ๏ธ position ์˜ˆ์‹œ (04_position.html)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="04_position css">
</head>
<body>
    <div class="blue"></div>
    <div class="red"></div>
    <div class="green"></div>
    <div class="parent">
        <div class="children"></div>
    </div>
    <div class="yellow">

    </div>
</body>
</html>

static

  • ์•„๋ฌด๊ฒƒ๋„ ์•ˆ์ ์€ ๊ธฐ๋ณธ๊ฐ’
  • ์•ˆ์›€์ง์ž„, absolute์˜ ๋ถ€๋ชจ๊ฐ€ ๋  ์ˆ˜ ์—†์Œ

relative

  • left: , right: , bottom, top ์š”์†Œ๋กœ ์ •ํ•œ ํฌ๊ธฐ๋งŒํผ ์›๋ž˜ ์žˆ์–ด์•ผํ•˜๋Š” ์œ„์น˜๋ฅผ ์ค‘์‹ฌ์œผ๋กœ ์—ฌ๋ฐฑ์„ ์คŒ
  • ์ „์ฒด ์˜์—ญ (๋งˆ์ง„, ๋ณด๋” ๋“ฑ)์ด ์ „๋ถ€ ์›€์ง์ž„, ์›๋ž˜ ์œ„์น˜์—๋„

absolute

  • ๋ถ€๋ชจ(body๊ฐ€ ๋ถ€๋ชจ์ผ ๊ฒฝ์šฐ ํ™”๋ฉด์˜ ์™ผ์ชฝ ์ƒ๋‹จ)๋ฅผ ์ค‘์‹ฌ์œผ๋กœ left: , right: , bottom, top ์š”์†Œ ํฌ๊ธฐ๋งŒํผ ์—ฌ๋ฐฑ์„ ์คŒ, ๊ทธ๋งŒํผ ๋–จ์–ด์ง
  • ๋ถ€๋ชจ๋ฅผ ์ค‘์‹ฌ์œผ๋กœ ์ด๋™ํ•จ,
  • ๋ถ€๋ชจ๋Š” position ์†์„ฑ์ด static์ด ์•„๋‹ˆ์—ฌ์•ผ ํ•จ, ๋ถ€๋ชจ ๋ฐ”๊นฅ์œผ๋กœ ๋‚˜๊ฐˆ ์ˆ˜๋„ ์žˆ์Œ

fixed(๊ณ ์ •์œ„์น˜)

  • ๋ถ€๋ชจ ์ž์‹ ๊ด€๊ณ„์—†์ด ๋ธŒ๋ผ์šฐ์ € ๋ทฐํฌํŠธ(์šฐ์ธก ์ƒ๋‹จ)๋ฅผ ์ค‘์‹ฌ์œผ๋กœ ์ด๋™ํ•จ
  • ์Šคํฌ๋กค์„ ์›€์ง์—ฌ๋„ ๋”ฐ๋ผ ์›€์ง์ž„, ์ƒ๋‹จ ๋ฉ”๋‰ด๋ฐ” ๊ฐ™์€๊ฑฐ ๋งŒ๋“ค ๋•Œ