์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- ๋ฐ์ํ
- css
- ํฐ์คํ ๋ฆฌ์ฑ๋ฆฐ์ง
- ๋๊ฐ
- ๋ฐฐ์์ ๋ฐฐ์
- ์นดํ๋๊ฐ
- ์นํผ๋ธ๋ฆฌ์ฑ
- ์ฝ๋ฉ
- ๋ฐ์ดํฐ๋ฒ ์ด์ค
- ์ค๋ผํด
- Java
- Python
- ์ํ์ฃผ
- ๊ฐ์ดํ ์ข ๋ญ๊ฐ๋น
- JavaScript
- ์๋ฐ
- ๊น๋ฏธ๊ฒฝ์๋งํ์์
- ์ํ
- database
- ์ ๋ฆฌํธ๋ฆฌํธ
- ๊ฐ๋ฐ
- html
- ์ฑ
- ๋ ์
- ํ์ฒ์ ๋ฆฌํธ๋ฆฌํธ
- ํ๋ก๊ทธ๋๋ฐ
- ์ค๋ธ์
- ํ์ด์ฌ
- ์๋ฐ์คํฌ๋ฆฝํธ
- K๋ฐฐํฐ๋ฆฌ๋ ๋ณผ๋ฃจ์
- Today
- Total
JiYoung Dev ๐ฅ
CSS position, ์คํ์ผ์ํธ ์ ์ธ ๋ฐฉ์ (2023.04.28) ๋ณธ๋ฌธ
CSS position, ์คํ์ผ์ํธ ์ ์ธ ๋ฐฉ์ (2023.04.28)
Shinjio 2023. 4. 28. 12:18๐ ์ด์ ๋ฐฐ์ด ๋ด์ฉ ์ ๋ฆฌ
Box Model
- Content : ๋ด์ฉ
- Padding : ์์ชฝ ์ฌ๋ฐฑ
- Border : ๊ฒฝ๊ณ์
- Margin : ๋ฐ๊นฅ ์ฌ๋ฐฑ
Box-Sizing
1. content-box (default) : content ๋งํผ๋ง์ ํฌ๊ธฐ๋ก ์ผ๋
2. border-box : border๊น์ง๋ฅผ ํฌ๊ธฐ๋ก ์ผ๋
=> ๋๋ ํจ๋ฉ๊ฐ์ ์ฃผ๊ณ ์ถ์ง๋ง, ์ ์ฒด์ ์ธ ํฌ๊ธฐ์๋ ์ํฅ์ ์ฃผ๊ณ ์ถ์ง ์์ ๋ ์ฌ์ฉ!
border-box
Border-Radius
- ํ ๋๋ฆฌ๋ฅผ ๋ฅ๊ธ๊ฒ ๋ง๋ค์ด์ฃผ๋ ์์ฑ
border-์/์๋-์ข/์ฐ-radius
Flex Box
- Container์ Item ์ ๋๋๋ ์์ ์ด ๋จผ์
- Item : ๋ด๊ฐ ์์ง์ด๊ณ ์ ํ๋ ์์
- Container : ์์ดํ ์ ๋ถ๋ชจ์์
a. container์ ์์ฑํด์ผํ ์์ฑ
> display : flex;
> ์ถ์ ๊ฒฐ์ ํ๋ ๊ฒ? flex-direction
- row : ๋ฉ์ธ (๊ฐ๋ก,x) ์๋ธ (์ธ๋ก,y)
- column : ๋ฉ์ธ (์ธ๋ก,y) ์๋ธ (๊ฐ๋ก, x)
> ๋ฉ์ธ์ถ ์ ๋ ฌ : justify-content
> ์๋ธ์ถ ์ ๋ ฌ : align-items
b. item ์ ์์ฑํด์ผํ ์์ฑ
> ์์ดํ ์ ํฌ๊ธฐ : flex-basis (%)
๐ CSS ์์น์์ฑ : position
์์ ์์ฌ๋ก ์์์ ์์น๋ฅผ ๋ฐฐ์นํ๋ ์์ฑ
position์ ์ฌ์ฉํ๊ธฐ ์ํด์๋ CSS์ ์์น์์ฑ์ ์์์ผ ํ๋ค.
(์)
top ์์ฑ : ์์์๋ถํฐ ์ผ๋ง๋ ๋จ์ด์ ธ ์๋๊ฐ.
top: 10px; ์๋จ์์๋ถํฐ 10px ๋จ์ด๋จ๋ฆฌ๊ฒ ๋ค
๐ position : static
position์ ๊ธฐ๋ณธ๊ฐ์ผ๋ก top, bottom, left, right ์์น๊ฐ ์ค์ ์ด ๋นํ์ฑํ๋จ
๐ position : relative
๋ณธ์ธ์ด ์๋ ์๋ ์์น๋ฅผ ๊ธฐ์ค์ผ๋ก top, bottom, left, right ์์น๊ฐ ์ค์ ์ด ํ์ฑํ๋จ
๐ position : absolute
static์ด ์๋ ๋ถ๋ชจ ์์๋ฅผ ๊ธฐ์ค์ผ๋ก top, bottom, left, right ์์น ์ค์ ํ์ฑํ
๋ง์ฝ, static์ด ์๋ ๋ถ๋ชจ ์์๊ฐ ์๋ค๋ฉด body๋ฅผ ๊ธฐ์ค์ผ๋ก!
๐ position : fixed
๋ถ๋ชจ ์์, ์คํฌ๋กค์ ๋ชจ๋ ๋ฌด์ํ๊ณ ์ต์์ ํ๊ทธ(body)๋ฅผ ๊ธฐ์ค์ผ๋ก top, bottom, left, right ์์น ์ค์ ํ์ฑํ
ํต๋ฉ๋ด๋ฅผ ๋ง๋ค ๋ ๋ง์ด ์ฌ์ฉ
<!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>
<style>
#parents div {
width: 100px;
height: 100px;
background-color: violet;
border: 1px solid black;
}
/* position : ์์ ์์ฌ๋ก ์์น๋ฅผ ๋ฐฐ์นํ๋ ์์ฑ */
#static{
/* (1) static : ์ ์ ์ธ
position ์์ฑ์ default ๊ฐ
์์น์์ฑ์ด ๋นํ์ฑํ๋์ด ์์ผ๋ฏ๋ก ์ค์ ๊ฐ์ ์ค๋ ์์ง์ด์ง ์๋๋ค!
=> ์์ง์ ์์ด ์์์ ์๋๋ก ์์์ฃผ๋ ์ญํ
=> ์ค์ ๋ก ์ฌ์ฉํ๋ ์ผ์ ์๋ค. */
top: 10px;
/* top : ๋งจ ์์์๋ถํฐ 10px ์ด๋ํด๋ผ
์ถ๋ฐ์ : top, ์ด๋๋ฐฉํฅ : ์๋๋ก */
left: 10px;
}
#relative{
/* (2) relative : ์๋์ ์ธ
์์น์์ฑ์ ํ์ฑํ๋ ์์
๊ธฐ์ค : ์๋ ๋ณธ์ธ์ด ์๋ ์์น
*/
position: relative;
top: 10px;
left: 10px;
}
#parents{
position: relative;
}
#absolute{
/* (3) absolute : ์ ๋์ ์ธ
์์น์์ฑ ํ์ฑํ
๊ธฐ์ค : static์ด ์๋ ๋ถ๋ชจ
-> ๋ถ๋ชจ ์์๊ฐ ์กด์ฌํ์ง ์๊ฑฐ๋, ๋ถ๋ชจ๋ static์ด๋ผ๋ฉด body ํ๊ทธ๋ฅผ ๊ธฐ์ค์ผ๋ก ํ๋ค.
*/
position: absolute;
top: 10px;
left: 10px;
/* ์์น ๊ฐ์ ์ฃผ์ง ์์์ ๋ ->
absolute ๋ฐ์ static ์์ฑ์ ๊ฐ์ง fixed๊ฐ ๊น๋ ค ์์ */
}
#fixed{
/* (4) fixed : ๊ณ ์ ์ ์ธ
์์น์์ฑ ํ์ฑํ. ์คํฌ๋กค ๋ฌด์!
๊ธฐ์ค : body ํ๊ทธ */
position: fixed;
bottom: 0px;
right: 0px;
}
</style>
</head>
<body>
<div id="top"></div>
body ํ๊ทธ ์์ชฝ
<div id="parents">
๋ถ๋ชจ ํ๊ทธ ์์ชฝ
<div id="static">static</div>
<div id="relative">relative</div>
<div id="absolute">absolute</div>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<h1>์ค๋์ ์ฆ๊ฑฐ์ด ๊ธ์์ผ!</h1>
<a href="#top">
<div id="fixed">fixed</div>
</a>
</div>
</body>
</html>
position ์ค์ต
<!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>
<style>
.square{
width: 100px;
height: 100px;
position: absolute;
/* absolute ์ฌ์ฉ ๊ฐ๋ฅ! --> body ํ๊ทธ๋ฅผ ๊ธฐ์ค์ผ๋ก ์์น ์ค์ ๋จ
(static์ด ์๋ ๋ถ๋ชจ์์๊ฐ ์์ผ๋ฏ๋ก)*/
}
#red{
background-color: red;
left: 0px;
top: 0px;
}
#yellow{
background-color: yellow;
right: 0px;
top: 0px;
}
#blue{
background-color: blue;
bottom: 0px;
left: 0px;
}
#green{
background-color: green;
right: 0px;
bottom: 0px;
}
</style>
</head>
<body>
<div id="parents">
<div class="square" id="red"></div>
<div class="square" id="yellow"></div>
<div class="square" id="blue"></div>
<div class="square" id="green"></div>
</div>
</body>
</html>
< ์ ๋ฆฌ >
๐ overflow
์์ ์ ๋ง์ด ์ฌ์ฉํ๋ ๋ฐฉ์
๋ถ๋ชจ ์์์ ๋ฒ์๋ฅผ ๋ฒ์ด๋ ๋ ์ด๋ป๊ฒ ์ฒ๋ฆฌํ ์ง ์ง์
<!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>
<style>
div{
width: 200px;
height: 200px;
background-color: lightgray;
/* overflow
๋ถ๋ชจ์์์ ๋ฒ์๋ฅผ ๋ฒ์ด๋ ๋ ์ด๋ป๊ฒ ์ฒ๋ฆฌํ ๊ฒ์ธ๊ฐ?
(1) visible : ๊ทธ๋๋ก ๋ณด์ฌ์ค (๊ธฐ๋ณธ๊ฐ)
(2) hidden : ์์ญ์ ๋ฒ์ด๋๋ฉด ์จ๊ฒจ์ค
(3) scroll : ์คํฌ๋กค ์ฒ๋ฆฌ
(4) auto : ์คํฌ๋กค์ด ํ์ํ๋ฉด ์คํฌ๋กค ์ฒ๋ฆฌ
ํ์ํ์ง ์์ผ๋ฉด X
*/
overflow : auto;
}
</style>
</head>
<body>
<div>
์ค๋์ ๊ธ์์ผ. ๋ด์ผ์ ํ ์์ผ. ์ฃผ๋ง์ ๋ญํ์ง. ๋ ์จ๊ฐ ์ข์ผ๋ฉด ์ข๊ฒ ๋ค.
์ฌํ๊ฐ๊ณ ์ถ๋ค. ๋ฐ๋ค๋ณด๋ฌ ๊ฐ๊ณ ์ถ๋ค. ์ด๋ฐฅ๋ทํ ๊ฐ๊ณ ์ถ๋ค
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
์๋
</div>
</body>
</html>
๐ float
์ต๊ทผ์๋ flex๋ฅผ ๋ง์ด ์.
์์๋ฅผ ๋์ด์ ๋ฐฐ์นํ๋ ์์ฑ
flex ์ float๋ ๊ฐ์ด ์ฐ์ง ์๋๊ฒ ์ข๋ค!
๐ ์คํ์ผ ์ํธ ์ ์ธ ๋ฐฉ์
๐ ์ธ๋ผ์ธ ์คํ์ผ
์์ ๋ด style ์์ฑ์ผ๋ก ์คํ์ผ ์ง์
์ ์ฌ์ฉํ์ง ์์ง๋ง ์ธ๋ผ์ธ ์คํ์ผ์ ์ฌ์ฉํ๋ ๋๊ฐ ์๋ค.
์ธ์ ? ๊ธํ๊ฒ ๋ณ๊ฒฝํด์ผ ํ ๋๋ง. ์ ์ ์ธ๋ผ์ธ ์คํ์ผ๋ก ๋ฐ๊พธ์๋ค๊ฐ ๋์ค์ ์ธ๋ถ ์คํ์ผ๋ก ๋ณ๊ฒฝ
๐ ๋ด๋ถ ์คํ์ผ
head ์์ ๋ด style ์์ ์์ฑ ํ ์คํ์ผ์ ์ง์
์ ์ฌ์ฉํ์ง ์๋๋ค! >>>> ๋ณด์์์ ๋ฌธ์ ๊ฐ ์๊ธฐ ๋๋ฌธ!
(๊ฐ๋ฐ์๋๊ตฌ์์ ์ฝ๋, ์ฃผ์๊น์ง ๋ค ๋ณผ ์ ์์)
>> ์ธ๋ถ๋ฐฉ์์ ์ฌ์ฉํ๋ค!
๐ ์ธ๋ถ ์คํ์ผ ๋ฐฉ์
css ํ์ผ์ ๋ฐ๋ก ์์ฑํ ํ html <head> ๋ด์ <link> ํ๊ทธ๋ก ์ฐ๊ฒฐํ์ฌ ์ฌ์ฉํ๋ ๋ฐฉ์
<link rel = "stylesheet" href="cssํ์ผ ์ฃผ์">
<!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>
<!-- ์ธ๋ถ ๋ฐฉ์
- ์ธ๋ถ์ css ํ์ผ์ ๋ง๋ค์ด์ html ๋ฌธ์์ ์ฐ๊ฒฐํ๋ ๋ฐฉ์
- ํ์ ์์ฑ rel, href
- rel : ๋ฌด์จ ๊ด๊ณ์ธ์ง
- href : ์ด๋์ ์๋์ง
-->
<link rel="stylesheet" href="./ex18์ธ๋ถ.css">
</head>
<body>
<!-- ์ธ๋ผ์ธ ๋ฐฉ์ : ๊ธด๊ธ์ ์ฌ์ฉ -->
<h1 style="color:violet">์ธ๋ผ์ธ ์ ์ธ ๋ฐฉ์</h1>
<h2>์ธ๋ถ ์ ์ธ ๋ฐฉ์</h2>
</body>
</html>
โผ cssํ์ผ โผ
h2{
color: purple;
}
h1{
color: red !important;
/* ์ธ๋ถ ์ฐ๊ฒฐ ๋ฐฉ์๋ณด๋ค ์ธ๋ผ์ธ ๋ฐฉ์์ด ๋ ์ฐ์ ์์๊ฐ ๋๋ค
--> !important ๋ฅผ ๋ค์ ๋ถ์ด๋ฉด ์ฐ์ ์์๊ฐ ๋์์ง๋ค.
--> ์ข์ ๋ฐฉ๋ฒ์ ์๋๋ค. */
}
/*
CSS ์ฐ์ ์์ ์ด ์ ๋ฆฌ
1) !important : ๊ฐ์ค์น๋ฅผ ์ธก์ ํ ์ X (๊ฐ์ฅ ๊ฐ๋ ฅํจ)
๋ค๋ง, ์ฐ์ ์์์ ๊ท์น์ฑ์ ํ๊ดดํ๊ธฐ ๋๋ฌธ์ ์ฌ์ฉํ๋๊ฑธ ์ถ์ฒํ์ง ์๋๋ค.
2) ์ธ๋ผ์ธ ์ฌ์ฉ ๋ฐฉ์ : ๊ฐ์ค์น 1000
๋ณด์์์ ๋ฌธ์ ๊ฐ ์๊ธฐ ๋๋ฌธ์ ๋ง์ด ์ฌ์ฉ๋์ง ์๋๋ค.
3) ์ธ๋ถ ์ฌ์ฉ๋ฐฉ์
์์ ์กฐ๊ฑด๋ค์ด ๋ชจ๋ ๊ฐ๋ค๊ณ ๊ฐ์ ํ ๋,
a) ์์ด๋ ์ ํ์ : ๊ฐ์ค์น 100
b) ํด๋์ค ์ ํ์ : ๊ฐ์ค์น 10
c) ํ๊ทธ ์ ํ์ : ๊ฐ์ค์น 1
d) * : ๊ฐ์ค์น 0
์์ ๋ชจ๋ ์กฐ๊ฑด์ด ์ ๋ถ ๊ฐ์ ๋
=> ๋์ค์ ์ ์ธ > ๋จผ์ ์ ์ธ
(๋์ค์ ์ ์ธํ๊ฒ ์ฐ์ ์์๊ฐ ๋ ๋๋ค)
*/
CSS ์ฐ์ ์์ ์ด ์ ๋ฆฌ (๋งค์ฐ ์ค์!!!!!!!!)
'full stack > HTML, CSS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
CSS ๋ฐ์ค๋ชจ๋ธ (2023.04.27) (0) | 2023.04.27 |
---|---|
CSS, HTML ๊ณต๊ฐ๋ถํ ํ๊ทธ (2023.04.26) (0) | 2023.04.26 |
HTML ํ๊ทธ : ๋ฆฌ์คํธ, ์ด๋ฏธ์ง, ์ต์ปค, ํ ์ด๋ธ, ์ธํ (2023.04.25) (0) | 2023.04.25 |
WEB & HTML ์ ์์ ์ญ์ฌ / HTML ํ๊ทธ (2023.04.21) (1) | 2023.04.23 |
CSS ๋ ์ด์์ : Position, Flex (0) | 2023.03.08 |