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

html, css

์ฝ”๋ˆ„๋‚˜๋‹˜ - HTML, CSS / chapter 5 - HTML์„ ์ข€ ๋” ์‰ฝ๊ฒŒ ์›€์ง์ด๋Š” ๋ฐฉ๋ฒ•

<position ์†์„ฑ์˜ ๊ฐ’๋“ค>

  • static : ์›น์‚ฌ์ดํŠธ์˜ ๊ธฐ๋ณธ ์†์„ฑ๊ฐ’(default ๊ฐ’) , top right bottom left ๋“ฑ ์œ„์น˜ ์†์„ฑ์€ ๋ฌด์‹œ๋จ.
  • relative: HTML ํƒœ๊ทธ๊ฐ€ ์žˆ๋Š” ์œ„์น˜์—์„œ left right top bottom๊ฐ’์„ ํ†ตํ•ด ์›€์ง์ž„ 
  • absolute: ๋ถ€๋ชจ์˜์—ญ์—์„œ left right top bottom ์„ ์ด์šฉํ•ด ์ ˆ๋Œ€๊ฐ’ ๊ธฐ์ค€์œผ๋กœ ์ฃผ์–ด์ง„ ์œ„์น˜๋กœ ์›€์ง์ž„ 
  • * ๋‹จ! ์—ฌ๊ธฐ์„œ ๋ถ€๋ชจ๋ž€?: ๋ถ€๋ชจ ํƒœ๊ทธ๊ฐ€ relative, absolute, fixed ์†์„ฑ ์ค‘ ํ•˜๋‚˜์—ฌ์•ผ ํ•จ. ๋งŒ์•ฝ ๋ถ€๋ชจํƒœ๊ทธ๊ฐ€ ํ•ด๋‹น ์†์„ฑ์„ ๊ฐ€์ง€๊ณ ์žˆ์ง€ ์•Š๋‹ค๋ฉด bodyํƒœ๊ทธ ๊ธฐ์ค€์œผ๋กœ ์›€์ง์ž„ ์™œ๋ƒํ•˜๋ฉด bodyํƒœ๊ทธ๋Š” relative๋ฅผ ๊ธฐ๋ณธ ์†์„ฑ์œผ๋กœ ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค 
  • fixed : absolute์™€ ๋น„์Šทํ•˜์ง€๋งŒ ์Šคํฌ๋กค๋กœ ๋‚ด๋ ค๋„ ๊ทธ ์œ„์น˜์— ๊ณ ์ •, ๋ฌด์กฐ๊ฑด ๋ธŒ๋ผ์šฐ์ € ์ฐฝ ๊ธฐ์ค€์ž„
  • Sticky : relative์™€ ๋น„์Šทํ•˜์ง€๋งŒ ์Šคํฌ๋กค๋กœ ๋‚ด๋ฆฌ๋ฉด fixed์ฒ˜๋Ÿผ ๊ทธ ์œ„์น˜์— ๊ณ ์ • 

 

์ผ๋‹จ ๊ธฐ๋ณธ ์ฝ”๋“œ

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href = "5-1style.css" rel = "stylesheet" type = "text/css" />
</head>
<body>
    <div class = "box red">
        box1
    </div>
    <div class = "box yellow">
        box2
    </div>
    <div class = "box blue">
        box3
    </div>
</body>
</html>
.box {
    width : 100px;
    height : 100px;
}

.red {
    background-color : red;
}

.yellow {
    background-color: yellow;
}

.blue {
    background-color: rgb(79, 96, 255);
}

 

 

 

# yellow ๋ฐ•์Šค์— locate ํด๋ž˜์Šค{ top : 30px; left : 30px; position : relative; }๋ฅผ ์ถ”๊ฐ€ํ–ˆ์„ ๋•Œ

 

 

 

yellow ๋ฐ•์Šค์— ์ถ”๊ฐ€๋œ locate ํด๋ž˜์Šค์˜ position์„ absolute๋กœ ๋ฐ”๊ฟจ์„ ๋•Œ

 

 

yellow ๋ฐ•์Šค์— ์ถ”๊ฐ€๋œ locate ํด๋ž˜์Šค์˜ position์„ static๋กœ ๋ฐ”๊ฟจ์„ ๋•Œ

- static์€ top, left, right, bottom ๋“ฑ์˜ ์œ„์น˜ ์†์„ฑ์€ ๋ฌด์‹œํ•œ ๊ทธ๋ƒฅ default ๊ฐ’์ด๋‹ค.

 

 

yellow ๋ฐ•์Šค์— ์ถ”๊ฐ€๋œ locate ํด๋ž˜์Šค์˜ position์„ fixed๋กœ ๋ฐ”๊ฟจ์„ ๋•Œ

- ์ด ์˜ˆ์ œ์—์„œ๋Š” absolute์™€ ๋ณ„ ๋ฐ˜ ๋‹ค๋ฅผ๊ฒŒ ์—†๋‹ค.

 

 

- ์Šคํฌ๋กค์ด ์ƒ๊ธธ ๋•Œ ๊นŒ์ง€ ๋ฐ•์Šค๋ฅผ ๋” ์ถ”๊ฐ€ํ–ˆ์„ ๋•Œ

ํ‰์†Œ์— ์‡ผํ•‘๋ชฐ ์‚ฌ์ดํŠธ์— ๋“ค์–ด๊ฐ€๋ณด๋ฉด ์Šคํฌ๋กค์„ ๋‚ด๋ ค๋„ ์ค„์ค„์ด ๋”ฐ๋ผ์˜ค๋Š” ์ง‘์ฐฉ๊ด‘๊ณต๊ฐ™์€ ๊ด‘๊ณ ๋‚˜, ํ€ต๋ฉ”๋‰ด ๋“ฑ๋“ฑ์ด ์ด fixed๋ฅผ ์ ์šฉํ•œ ์‚ฌ๋ก€๋“ค๋กœ ๋ณผ ์ˆ˜ ์žˆ๊ฒ ๋‹ค.

 

์ง‘์ฐฉ๊ด‘๊ณต box..

์—ฌ๊ธฐ์„œ position์„ absolute๋กœ ๋ฐ”๊พธ๋ฉด ์Šคํฌ๋กค์„ ๋‚ด๋ ค๋„ ๋นจ๊ฐ„๋ฐ•์Šค ์œ„์— ๊ฒน์ณ์ ธ ์•ˆ๋ณด์ด๊ฒŒ ๋จ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. (์•ˆ ๋”ฐ๋ผ์˜ด)

 

yellow ๋ฐ•์Šค์— ์ถ”๊ฐ€๋œ locate ํด๋ž˜์Šค์˜ position์„ sticky๋กœ ๋ฐ”๊ฟจ์„ ๋•Œ

 

์œ„ 30px๊ฐ€ ๋˜์ž๋งˆ์ž ๊ทธ ์ž๋ฆฌ์— ๋”ฑ ๋ถ™์–ด์„œ ๋‚ด๋ ค์˜ค๋Š” ๋ชจ์Šต, ๋‹ค์‹œ ์ญˆ์šฑ ์˜ฌ๋ฆฌ๋ฉด ์ฒ˜์Œ ์ž๋ฆฌ๋กœ ๋Œ์•„๊ฐ„๋‹ค.

 

<display : flex>

 

์–˜๋Š” ๋‚ด๊ฐ€ ํ˜„์žฅ์‹ค์Šต ๋•Œ ์ง์›๋ถ„์ด ๋Œ€์ถฉ ์จ๋†“์€ ์ฝ”๋“œ ๋•๋ถ„์— ์กด์žฌ๋ฅผ ์•Œ๊ฒŒ ๋๋Š”๋ฐ, display๋ผ๊ณ ๋Š” ํ•™๊ต์—์„œ ๋ฐฐ์šด ์ธ๋ผ์ธ ๋ธ”๋ก ์ธ๋ผ์ธ๋ธ”๋ก๋ฐ–์— ๋ชฐ๋ž์–ด์„œ ์ •๋ง ์‹ ์„ธ๊ณ„์˜€๋‹ค. ๊ทธ ๋•Œ ์ง„์งœ ์ฃฝ์–ด๋ผ ๋ด์„œ ์‹ค์Šต์€ ํŒจ์Šค, ๊ฐ•์˜๋กœ๋งŒ ๋ณด๊ธฐ๋กœ

 

๊ฐ•์‚ฌ๋‹˜์ด ์ถ”์ฒœํ•˜์‹  flex ์—ฐ์Šต ์‚ฌ์ดํŠธ : https://flexboxfroggy.com/#ko

๋‚ด๊ฐ€ ์ •๋ง ์ •๋ง ๋„์›€ ๋งŽ์ด ๋ฐ›์€ ํฌ์ŠคํŒ… : https://studiomeal.com/archives/197

ใ„ด ์ด๊ฑฐ ์ง„์งœ ์˜ฌํ•ด์˜ ๋ฌธํ•™(?)์ƒ ๋ฐ›์•„์•ผํ•  ์ •๋„๋กœ ์ตœ๊ณ  ... ์œ ๋ฃŒ ๊ฐ•์˜๋„ ํ•˜์‹œ๋˜๋ฐ ์ผ๋‹จ ์ด ํฌ์ŠคํŒ…๋งŒ์œผ๋กœ๋„ ์ถฉ๋ถ„ํ•œ๋“ฏ. 

๊ทธ ๋•Œ display ์†์„ฑ ์ค‘ grid๋„ ๊ฐ™์ด ํฌ์ŠคํŒ…ํ•˜์‹  ๊ฒƒ๋„ ์—ด์‹ฌํžˆ ๋ดค์—ˆ๋Š”๋ฐ ์–˜๋Š” ์กฐ๊ธˆ.. ๊ผผ๊ผผํ•˜์ง€ ๋ชปํ•œ ๋‚˜ํ•œํ… flex๊ฐ€ ์ข€ ๋” ์‹ค์šฉ์ ์ธ ๊ฒƒ ๊ฐ™์•„์„œ ์ผ๋‹จ ํŒจ์Šคํ–ˆ์—ˆ๋‹ค. ๋‚˜๋‚˜๋‹˜๋„ ์ž˜ ์„ค๋ช…ํ•ด์ฃผ์…จ๋Š”๋ฐ ๋‚˜์ค‘์— ๊ธฐํšŒ๋˜๋ฉด grid๋กœ ํ•œ๋ฒˆ ์‚ฌ์ดํŠธ๋ฅผ ๋งŒ๋“ค์–ด ๋ณด๋Š” ๊ฒƒ๋„ ๋‚˜์˜์ง€ ์•Š๊ฒ ๋‹ค.

https://d2.naver.com/helloworld/8540176 << ์—ฌ๊ธฐ๋„ flex๋ฅผ ์ด์šฉํ•œ ์—ฌ๋Ÿฌ ๋ ˆ์ด์•„์›ƒ์„ ์†Œ๊ฐœ์‹œ์ผœ์ฃผ๋Š”๋ฐ ๋„์›€๋˜๋Š”๋“ฏ.

 

 

 

1๋ถ„์ฝ”๋”ฉ๋‹˜ ๋•๋ถ„์— ๊ฐœ๋…์€ ์žก์•˜๋Š”๋ฐ ์‚ฌ์‹ค ๊ฐœ๋ฐœ์ž ๋„๊ตฌ๋กœ ์ด๊ฒƒ ์ €๊ฒƒ ์ ์šฉํ•ด๋ณธ๊ฒŒ ์ •๋ง ๋งŽ์€ ๋„์›€์ด ๋์—ˆ๋˜ ๊ธฐ์–ต์ด ๋‚œ๋‹ค.

์ฝ”๋”ฉ์€ ์ผ๋‹จ ํ•ด๋ด์•ผ ์‹ค๋ ฅ์ด ๋Š˜์–ด๋‚œ๋‹ค๋Š”๊ฒŒ ๋งž๋Š”๋“ฏ (๊ทผ๋ฐ ๊ท€์ฐฎ๋‹ค.)

 

 

 

 

 

<๋ฌธ์ œ 1>

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href = "5-1style.css" rel = "stylesheet" type = "text/css" />
</head>
<body>
    <div class = "box box1">
        box1
    </div>
    <div class = "box box3">
        box3
    </div>
    <div class = "box box2">
        box2
    </div>
</body>
</html>

๋‚˜๋Š” ๋ฌธ์ œ 1๋ฒˆ์—์„œ๋งŒ box 2๊ฐ€ ๋’ค์—์žˆ์–ด์•ผ ๊ฒฐ๊ณผ๊ฐ€ ์ œ๋Œ€๋กœ ์ถœ๋ ฅ๋˜๋”๋ผ,,, ๋‹ต์•ˆ ์ฝ”๋“œ๋ณด๊ณ  ๋ญ๊ฐ€ ๋ฌธ์ œ์ธ์ง€ ๋‹ค ํ’€๊ณ  ๋ด์•ผ๊ฒ ๋‹ค.

html ์ฝ”๋“œ๋Š” ๋‚จ์€ ๋ฌธ์ œ ์ค‘์—๋„ box3์˜ ์œ ๋ฌด ์ฐจ์ด๋งŒ ์žˆ๋Š” ์ •๋„๋Š” ์ƒ๋žตํ•˜๊ฑฐ๋‚˜ ์ฐจ์ด๊ฐ€ ์žˆ๋”๋ผ๋„ <body>์•ˆ ๋‚ด์šฉ๋งŒ ์ ๋„๋ก ํ•˜๊ฒ ๋‹ค.

 

html, body {
    padding : 0;
    margin : 0;
}

.box {
    display : inline-block;
    position: relative;
    margin : 0;
    width : 100px;
    height : 100px;
    background-color: black;
    color : #fff;
}

.box1 {
    float : left;
}

.box2 {
    margin-right : 10px;
    float : right;
}

.box3 {
    float : right;
}

 

 

<๋ฌธ์ œ 2>

 

html, body {
    padding : 0;
    margin : 0;
}

.box {
    display : block;
    position: relative;
    margin : 0;
    width : 100px;
    height : 100px;
    background-color: black;
    color : #fff;
}

.box1 {
    top : 0px;
    left : 0px;
}

.box2 {
    margin: 0 auto;
}

.box3 {
    float:right;
}

 

 

<๋ฌธ์ œ 3>

 

<div class = "box box1">
    box1
    <div class = "box box2">
        box2
    </div>
</div>

.box {
    position: relative;
    color : #fff;
}

.box1 {
    width : 200px;
    height : 200px;
    margin : 30px auto;
    background-color: black;
}

.box2 {
    width : 100px;
    height : 100px;
    margin : auto;
    position : absolute;
    transform: translateX(-50%) translateY(-50%);
    left : 50%;
    top : 50%;
    background-color: #333;
    vertical-align: middle;
}

 

 

<๋ฌธ์ œ 4>

 

<div class = "box box1">
    box1
</div>

<div class = "box box2">
    box2
</div>

html, body {
    padding : 0;
    margin : 0;
}

.box {
    width : 100px;
    height : 100px;
    position: relative;
    margin : 0;
    color : #fff;
}

.box1 {
    background-color: black;
}

.box2 {
    position: absolute;
    background-color: #333;
    top : 50px;
    left : 50px;
}

 

 

<๋ฌธ์ œ 5>

 

html, body {
    padding : 0;
    margin : 0;
}

.box {
    position: absolute;
    margin : 0;
    color : #fff;
}

.box1 {
    bottom : 0;
    right : 0;
    width : 400px;
    height : 250px;
    background-color: black;
}

.box2 {
    width : 150px;
    height : 150px;
    position: absolute;
    bottom : 0;
    background-color: #333;
}

.box3 {
    width : 150px;
    height : 150px;
    position: absolute;
    margin : auto 0;
    right : 0;
    top : 0;
    background-color: #333;
}

 

<div class = "box box1">
    box1
    <div class = "box box2">
        box2
    </div>
    <div class = "box box3">
        box3
    </div>
</div>

 

 

 

----

 

 

 

์ •๋‹ต์„ ๋ณด๊ณ ์™”๋Š”๋ฐ ์ €๋ฒˆ ๊ตฌ๊ธ€์‚ฌ์ดํŠธ๋•Œ๋Š” flex ๋‚จ๋ฐœ์„ ํ–ˆ์œผ๋ฉด์„œ ์ด๋ฒˆ์—” ์™œ ํ•˜๋‚˜๋„ ์•ˆ์ผ์„๊นŒ.....

์–ดํœด... ๋‚ด์ผ ์ผ์–ด๋‚˜์„œ ์‹œ๊ฐ„๋‚จ์œผ๋ฉด ๋‹ค์‹œ flex๋กœ ์ฝ”๋“œ๋ฅผ ์งœ๋ด์•ผ๊ฒ ๋‹ค.

 

์ •๋‹ต ๋งํฌ : https://hackmd.io/@oW_dDxdsRoSpl0M64Tfg2g/rJ91twR1K

 

Css ์‹ฌํ™”: ํƒœ๊ทธ๋ฅผ ๋‚ด๋ง˜๋Œ€๋กœ ์œ„์น˜์‹œํ‚ค๊ธฐ challenge ์ •๋‹ต - HackMD

# Css ์‹ฌํ™”: ํƒœ๊ทธ๋ฅผ ๋‚ด๋ง˜๋Œ€๋กœ ์œ„์น˜์‹œํ‚ค๊ธฐ challenge ์ •๋‹ต ## ๋„์ „ 1 ์ •๋‹ต ![](https://i.imgur.com/Yy2i9sJ.png) * HTML ```htm

hackmd.io