CSS-1
CSS-1
~์น์ ์ธ์ด๋ค๋ก ๊ตฌ์ฑ๋์ด ์๋ค. ๊ฐ์ฅ ํฌ๊ฒ 3๊ฐ์ง๋ก ๋๋๋ฉด, HTML, CSS, JavaScript๊ฐ ์๋ค.
HTML: ๋ผ๋, CSS: ๊ทผ์ก, JavaScript: ๋
CSS : Cascading Style Sheet, ์์๋๋ก ๋ ์คํ์ผ ์ํธ์ด๋ค.
ํ๊ทธ๋ฅผ ์ค๋ณตํด์ ๋ง๋ค์๋ค๋ฉด ์ฝ๋์ ๊ฐ์ฅ ๋ง์ง๋ง ๋ถ๋ถ์ด ์คํ์ผ๋ก ์ ์ฉ๋๋ค.
์ธ์ธ ํ์์๋ค. ๋ชจ๋ฅด๋ ์ ํ์ด ๋์ค๋ฉด Google, MDN์ ์ฐพ์๋ณด์.
Do not memorize !
Add CSS to HTML
- HTML์ CSS ์คํ์ผ ์ํธ๋ฅผ ์ ์ฉํ๋ ๋ฐฉ๋ฒ์ด ์๋๋ฐ, 2๊ฐ์ง ๋ฐฉ๋ฒ์ด ์๋ค.
- ์๋ก์ด ์คํ์ผ ์ํธ๋ฅผ ๋ง๋๋ ๊ฒ
- HTML ๋ฌธ์์ ์คํ์ผ ์ํธ๋ฅผ ๋ง๋๋ ๊ฒ.
<head>
<title>Home - My first website.</title>
<!-- first case -->
<link rel="stylesheet" href="style.css" />
<!-- second case -->
<style></style>
</head>
Writing Our First CSS Lines
- CSS๋ HTML ๋ฌธ์์ ์๋ ํ๊ทธ๋ฅผ ๊ฐ๋ฆฌํค๊ณ ์ค๊ดํธ๋ฅผ ์ด์ฉํด์ ๊ทธ ์์ ์์ฑ์ ์จ์ค๋ค.
<style>
h1 {
color: blue;
font-style: italic;
font-size: 20px;
}
</style>
Blocks and Inlines
- Block์ ๋ค๋ฅธ ์์๊ฐ ์์ ์ค์ง ๋ชปํ๋ ๊ฒ์ ์๋ฏธํ๊ณ , Inlines๋ ๋ค๋ฅธ ์์๊ฐ ์์ ์ฌ ์ ์๋ ๊ฒ์ ์๋ฏธํ๋ค.
Block์ ์๋ก๋ <div>, <blockquote>, <header> โฆ
Inline์ ์๋ก๋ , ,
๊ฐ ์๋ค.
Margin-1
- Block์ inline์ฒ๋ผ ๋ง๋ค ์ ์๋ ๊ฒ? display: inline
- inline์ block์ฒ๋ผ ๋ง๋ค ์ ์๋ ๊ฒ? display: block
- ๋ธ๋ผ์ฐ์ ๋ ๊ธฐ๋ณธ์ ์ผ๋ก ์คํ์ผ ์์ฑ์ ์ค๋ค.
- Block : margin, border, padding
- Margin์ box์ ๊ฒฝ๊ณ ๋ฐ๊นฅ์ชฝ์ ์๋ค. body๋ ๊ธฐ๋ณธ์ ์ผ๋ก body๋ผ๋ box์ boder๋ฐ๊นฅ์ 8px์ ์ฌ๋ฐฑ์ ๊ฐ์ง๊ณ ์๋ค. (default)
Margin-2
-
margin: num โ> ์ฌ๋ฐฉ์ margin์ ์ค๋ค.
margin: num1 num2 โ> ์ ์๋์ num1 ์ข์ฐ์ num2๋งํผ์ margin์ ์ค๋ค.
margin: num1 num2 num3 num4 โ> ๊ฐ๊ฐ ์, ์ค๋ฅธ, ์๋, ์ผ์ชฝ์ margin์ ์ค๋ค. -
์์ ๊ทธ๋ฆผ์์ ํ์์ ๋ฐ์ค(div๋ฐ์ค) ์ ์ด๊ตฌ์ ๋ฐ์ค(body ๋ฐ์ค) ๊ฐ top๊ฒฝ๊ณ์์ ๊ฒน์ณ์์ ๋,
ํ์์ ๋ฐ์ค์ top์ margin์ ์ฃผ๋ฉด, body ๋ฐ์ค๊น์ง ์ ์ฒด๊ฐ ๋ธ๋ ค ๋ด๋ ค์ค๊ฒ๋๋ค. -
์ด ํ์์ Collapsing Margin ์ด๋ผ๊ณ ํ๋ฉฐ, ์๋ก ๋ถ๋ฆฌํ๊ธฐ ์ํด์ Padding์ด๋ผ๋ ๊ฐ๋ ์ด ํ์ํ๋ค.
-
Pading and IDs
- Padding์ ๊ฒฝ๊ณ์ ์์ชฝ ๊ณต๊ฐ์ด๋ค.
Padding์ margin์ ์ค๋ค๋ฉด border๋ถ๋ถ์ด ๊ฒน์น์ง ์๋๋ค.
๋ค์๊ณผ ๊ฐ์ด ๊ฐ ํ๊ทธ์ id๋ฅผ ์ฃผ๊ณ div์์ div๋ฅผ ๋ฐฐ์นํด๋ฌ ๊ฐ ๊ฒฝ๊ณ์ ์์์ ๋ค๋ฅด๊ฒ ์ฃผ์๋ค.
๊ทธ๋ฆฌ๊ณ padding margin์ ์ฃผ๋ฉด์ ์๋ก ๋ค๋ฅธ box์ธ ๊ฒ์ ๋ณด์ฌ์ค๋ค.
- Padding์ ๊ฒฝ๊ณ์ ์์ชฝ ๊ณต๊ฐ์ด๋ค.
-
<style>
html {
background-color: tomato;
}
body {
/* margin: 0px; */
padding: 10px;
background-color: wheat;
/* margin: 0; */
}
div {
margin-top: 10px;
margin-left: 10px;
width: 10px;
height: 10px;
padding: 10px;
background-color: red;
}
#first {
background-color: teal;
width: 150px;
height: 150px;
}
#second {
background-color: orange;
width: 100px;
height: 100px;
}
#third {
background-color: purple;
width: 50px;
height: 50px;
}
#fourth {
background-color: red;
width: 25px;
height: 25px;
}
</style>
</head>
<body>
<div id="first">
<div id="second">
<div id="third">
<div id="fourth"></div>
</div>
</div>
</div>
</body>
Border
-
Border์ ๊ฒฝ๊ณ๋ฅผ ์๋ฏธํ๊ณ , CSS๋ฅผ ํตํด ํฌ๊ธฐ์ ์์ ์ง์ ํ ์ ์๋ค.
-
โ*โ ์ ๋ชจ๋ box์ ์ ์ฉํ๋ค๋ ์๋ฏธ์ด๋ค.
* { border: 2px solid black; }
-
border์ inline ๊ณผ block ๋ชจ๋์ ์ ์ฉ๋๋ค. ( (์ธ๋ผ์ธ) , <div> (๋ธ๋ฝ) ์ ๊ฐ์ ํ๊ทธ๋ค ) ๊ทธ๋ ๋ค๋ฉด inline์์ margin, padding์ ์ ์ฉ์ด ๋ ๊น??
- Inline์์๋ margin์ด ์ ์ฉ๋๋ ๋ถ๋ถ์ด ํ์ ์ ์ด๋ค. inline์ ๋์ด์ ๋๋น๊ฐ ์๊ธฐ ๋๋ฌธ์ margin์ด ์ ์ฉ๋๋ฉด ์ข, ์ฐ์๋ง ์ ์ฉ๋๋ค. โ> ๋ฐ๋ผ์ ์ํ์ ๋ง์ง์ ์ ์ฉ์ํค๊ณ ์ถ์ ๊ฒฝ์ฐ block์ผ๋ก ๋ฐ๊ฟ์ margin์ ๋ฃ์ด์ฃผ์ด์ผํ๋ค.
- padding์ ๊ฒฝ์ฐ ์ฌ๋ฐฉ์ ์ ์ฉ์ด ๋๋ค.
Classes
-
class
- id์ ๊ฒฝ์ฐ ํ๋์ ํ๊ทธ๋น ํ๋์ id๋ง ์ ์ฉ๋๋ค. ํ์ง๋ง class์ ๊ฒฝ์ฐ ๋ค์ํ ํ๊ทธ๋ค์ ์ ์ฉ์ํฌ ์ ์๋ค.
๋ํ, class์ ๊ฒฝ์ฐ, ํ๊ทธ์ ์ฌ๋ฌ๊ฐ์ง ํด๋์ค๋ฅผ ๋์์ ๊ฐ์ง ์ ์๋ค.
id๋ฅผ ์ด์ฉํ ๊ฒฝ์ฐ #์ ์จ์ style์ ์ง์ ํด์ค๋ค.
class๋ฅผ ์ด์ฉํ ๊ฒฝ์ฐ .์ ์จ์ style์ ์ง์ ํด์ค๋ค.
#tomato = id=โtomatoโ .tomato = class=โtomatoโ
- id์ ๊ฒฝ์ฐ ํ๋์ ํ๊ทธ๋น ํ๋์ id๋ง ์ ์ฉ๋๋ค. ํ์ง๋ง class์ ๊ฒฝ์ฐ ๋ค์ํ ํ๊ทธ๋ค์ ์ ์ฉ์ํฌ ์ ์๋ค.
๋ํ, class์ ๊ฒฝ์ฐ, ํ๊ทธ์ ์ฌ๋ฌ๊ฐ์ง ํด๋์ค๋ฅผ ๋์์ ๊ฐ์ง ์ ์๋ค.
<style>
span {
margin: 5px;
border-style: dotted;
font-size: 15%;
}
.btn {
padding: 5px 5px;
border-radius: 5px;
}
.teal {
background-color: teal;
}
.tomato {
background-color: tomato;
color: white;
}
</style>
</head>
<body>
<span class="btn tomato"> hello </span>
<span class="btn teal"> hello </span>
<span class="btn tomato"> hello </span>
<span class="btn teal"> hello </span>
<span class="btn tomato"> hello </span>
<span class="btn teal"> hello </span>
inline-block
- Display์ ์ข ๋ฅ์๋ inline, block, inline-block์ด ์๋ค.
- inline์ ๊ฒฝ์ฐ ๋์ด์ ๋๋น๊ฐ ๋ฌด์๋์ด display๋์ง ์๊ณ ,
block์ ๊ฒฝ์ฐ ์์ผ๋ก ๋๋ํ ๋์ค๊ฒ ํ์ง ๋ชปํ๋ค.
inline-block์ ๊ฒฝ์ฐ block์ ๋ชจ์์ ๊ฐ์ง๋ฉด์ ์์ผ๋ก ๋๋ํ ์ค๊ฒํ ์ ์๋ค. - inline-block์ ๋จ์ ์.. ๊ทธ ์ฌ์ด margin์ ์ ํํ ๊ท์น์ด ์๋ค.
๋ฐ์ํ ์น์ฌ์ดํธ์์ ๋ฌ๋ผ์ง๋ค.
display: inline-block;
Flexbox-1
-
inline-Block์ ๋จ์ ์ ํด๊ฒฐํ๊ธฐ ์ํด์ display: flex๋ผ๋ ๊ฒ์ ์ด๋ค.
๋จ, ๋ถ๋ชจ element(div์ ๊ฒฝ์ฐ body)์์๋ง ๋ช ์ํ๋ค! -
justify-content / align-center ๋ฅผ ํตํด block์ ์์ฑ์ ๊ฒฐ์ ํด์ค๋ค.
justify-content ๋ main-axis(์ํ ๋ํดํธ) ์ ์ฉ, align-items๋ cross-axis(์์ง ๋ํดํธ)์ ์ ์ฉํ๋ค. -
์ฃผ์ํด์ผํ ๊ฒ์ justify-content๋ main-axis์ ์ ์ฉ๋ ๋ฟ, โ์ํโ์ ์ ์ฉ๋๋ ๊ฒ์ด ์๋๋ผ๋ ์ ์ด๋ค.
์๋ํ๋ฉด main-axis๋ก ์ํ ์์ง์ ๋ฐ๊ฟ ์ ์๊ธฐ ๋๋ฌธ์ด๋ค. -
vh ( viewport height )๋ก ํ๋ฉด ๋น์จ์ ๋ํ๋ธ๋ค.
( ์๋ ์์๋ ํ๋ฉด ๋น์จ์ 100%๋ฅผ ๋ํ๋ธ ๊ฒ )
<style>
body {
height: 100vh;
margin: 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
div {
width: 300px;
height: 300px;
background-color: teal;
}
</style>
Flexbox-2
-
flex-direction์ ํตํด main-axis์ ์ถ์ ์ํ ์์ง ์์น๋ฅผ ๋ณ๊ฒฝ์ํฌ ์ ์๋ค.
(column, row, column-reverse, row-reverse)
main-axis์ default๋ ? flex-direction: row ๋ผ๊ณ ์๊ฐํ์. -
div๋ด์ ์ปจํ ์ธ ๋ฅผ flex์ปจํ ์ด๋๋ก ๋ง๋ค๊ธฐ ์ํด์ div ๋ฐ์ค ๋ด์์ flex๋ฅผ ๋ช ์ํด์ผํ๋ค.
-
flex-wrap ๊ธฐ๋ฅ์ wrap์ ๋ฐ์ํ ์นํ์ด์ง์์ ํฌ๊ธฐ๊ฐ ๋ณํ๋๊ณ ์์น๊ฐ ๋ฐ๋๊ฒ ํด์ค๋ค.
<style>
body {
height: 100vh;
margin: 20px;
display: flex;
justify-content: space-between;
align-items: center;
flex-direction: column;
flex-wrap: wrap;
}
div {
display: flex;
justify-content: center;
align-items: center;
width: 300px;
height: 300px;
color: black;
font-size: 100px;
background-color: teal;
}
#mid {
background-color: wheat;
}
</style>
</head>
<body>
<div>1</div>
<div id="mid">2</div>
<div>3</div>
</body>
Position
-
position: fixed๋ block์ด ํ์ฌ ์์น์ ๊ณ ์ ๋์ด์๋ ์ํ
-
1000vh๋ฅผ ์ค์ ํ๋ฉด์ ๊ธธ์ด๋ฅผ ๊ธธ๊ฒํ๊ณ green๋ง position์
fix์ํค๋ฉด ์คํฌ๋กค์ ๋ด๋ ค๋ ๋ ์ด์์์ ์๊ด์์ด ๊ณ์ ๋ฐ๋ผ์จ๋ค. ex) netflix platform
<style>
body {
height: 1000vh;
margin: 20px;
}
div {
width: 300px;
height: 300px;
color: white;
background-color: teal;
opacity: 0.5;
}
#green {
position: fixed;
}
#different {
background-color: wheat;
}
</style>
</head>
<body>
<div id="green"></div>
<div id="different"></div>
</body>
Relative, Absolute
-
position: relative : ์ฒซ ์์น๋ฅผ ๊ธฐ์ค์ผ๋ก ์ํ์ข์ฐ ์์ง์์ ๋ง๋ค์ด์ค.
- position: absolute : ๊ฐ์ฅ ๊ฐ๊น์ด relativeํ ๋ถ๋ชจ๋ฅผ ๊ธฐ์ค์ผ๋ก ์์น๋ฅผ ์์ง์ธ๋ค.
๋ถ๋ชจ์๊ฒ relative๊ฐ ์๋ค๋ฉด body๊ฐ ๊ธฐ์ค์ด ๋๋ค. (body๋ relative๊ฐ ์๋ค๋ฉด vh๋ฅผ ๋ํ๋ ๋๊น์ง ๊ฐ์ง ์๋๋ค.) - position: static : default
Pseudo Selector-1
- first-child, Last-child, nth-child()
- ๋ฐ๋ณต๋๋ ํ๊ทธ๋ค์์ ํน์ ๊ท์น์ ๊ฐ์ง ํ๊ทธ๋ฅผ ๊ณ ๋ฅด๊ฑฐ๋,
ํ๊ทธ๋ฅผ ์ง์ ์ ํํ๊ณ ์ถ์ ๋, pseudo selector๋ฅผ ์ฌ์ฉํ์.
<style>
span:nth-child(3n + 1) {
background-color: tomato;
}
span:last-child {
background-color: teal;
}
</style>
Pseudo Selectors-2
- class ๋ฅผ ์ฐ์ง ์๊ณ input์ ์๋ attribute๋ฅผ ์ด์ฉํ์ฌ style์ ์ง์ ํ๋ ๋ฐฉ๋ฒ์ด๋ค.
- ~= โnameโ โ> โnameโ์ ํฌํจํ ๋ฌธ์๋ค์ ๊ฐ์ง๊ณ ์๋ input
- attribute์ ํน์ฑ์ ํ์ฉํ ๋, ๋ค์๊ณผ ๊ฐ์ด ์ด์ฉํ๋ค. ex) [placeholder], :required
input[placeholder~="name"] {
background-color: thistle;
}
input:required {
border-color: tomato;
}
Combinators
- ๋ถ๋ชจ ๋ฐ์ ์์์ ์ ํํ ๊ฒฝ์ฐ : p span
- ๋ถ๋ชจ ๋ฐ๋ก ๋ฐ์ ์์์ ์ ํํ ๊ฒฝ์ฐ : p > span
- ์์ ๋ฐ๋ก ์์ ํ์ ๋ฅผ ์ ํํ ๊ฒฝ์ฐ : p + span
- ์์ ์์ ํ์ ๋ฅผ ์ ํํ ๊ฒฝ์ฐ : p ~ span
<style>
p > span {
background-color: teal;
text-decoration: line-through;
}
p + span {
background-color: teal;
text-decoration: line-through;
}
p span {
background-color: teal;
text-decoration: line-through;
}
p ~ span {
background-color: teal;
text-decoration: line-through;
}
</style>
<body>
<p>hi baby <span>inside</span></p>
<span>hello</span>
</body>
States
-
active ( ๋๋ ์ ๋ (๋ฒํผ) )
hover ( ํค๋ณด๋๊ฐ ๊ฐ๋ฆฌํจ ์ํ )
focus ( ํค๋ณด๋ ๋์ )
visit ( ๋ฐฉ๋ฌธํ์ ๋) -
form:focus-within ( element๊ฐ focus๋๋ฉด ๋ฐ์์ด ๋๋ค. )
form:hover input:focus ( form์ ์ฌ๋ผ ์์ผ๋ฉด์ input์ ํค๋ณด๋ ๋์์ด ์์๋ ๋ ) -
attribute
- ::placeholder (placeholder์ ํน์ฑ๋ง ๋ฐ๊พธ๊ณ ์ถ์ ๋ ์ฌ์ฉํฉ๋๋ค.)
::selection (ํด๋ฆญํด์ ๊ธ์ ๋ ๋ฐ์ํฉ๋๋ค.)
::first-letter (์ฒซ ๊ธ์์๋ง ์ ์ฉ๋ฉ๋๋ค.)
::first-lines (์ฒซ ์ค์๋ง ์์ฉํฉ๋๋ค.)
- ::placeholder (placeholder์ ํน์ฑ๋ง ๋ฐ๊พธ๊ณ ์ถ์ ๋ ์ฌ์ฉํฉ๋๋ค.)
<style>
form:hover input:focus {
background-color: sienna;
}
form:focus-within {
border-color: silver;
}
button:active {
color: red;
}
</style>
Color and Variabels
- Color์ ํํ ๋ฐฉ์์ 3๊ฐ์ง๊ฐ ์๋ค.
- hexadeciamal color(color code)
- rgb(252, 206, 0)
- rgba (252, 206, 0, 1) (a๋ ํฌ๋ช ๋๋ฅผ ๋ํ๋ธ๋ค.)
- custom properties : color๋ฅผ ๋ณ์ํํด์ ์ด์ฉํ๋ ๋ฐฉ๋ฒ์ด๋ค.
<style>
:root {
--main-color: #fcce00;
--default-border: 1px solid var(--main-color);
}
a {
color: var (--default-border);
}
</style>