[2023.03.02] 2. CSS ์ ์ฉํ๊ธฐ
2023. 3. 2. 17:35ใDev./CSS
๐CSS๋ฅผ ์ ์ฉํ๋ ๋ค์ํ ๋ฐฉ๋ฒ๋ค์ ์์๋ณด์
1. ์ธ๋ผ์ธ ๋ฐฉ์
<p style="color: red; background-color: blue;">Hello world</p>
- ํ๊ทธ ์์ฒด์ style ์์ฑ์ผ๋ก ์คํ์ผ์ ์ฃผ๋ ๋ฐฉ์.
- ๊ฐ์ ์์(:hover, ::before, ::after ๋ฑ)์ ์คํ์ผ์ ์ค ์ ์์ด ์ฌ์ฉ์ ์ ํ์ด ์๋ค.
2. ๋ด๋ถ ์คํ์ผ
...
<head>
...
<style>
p {
color: red;
background-color: blue;
}
</style>
</head>
<body>
<p>Hello World</p>
</body>
...
- html ํ์ผ ์์ head ํ๊ทธ ๋ด์์ style ํ๊ทธ๋ฅผ ์ ์ํ์ฌ ์คํ์ผ์ ์ ์ฉํ๋ ๋ฐฉ์
- ์ฝ๋๊ฐ ๊ธธ์ด์ง์๋ก html ํ์ผ ๊ธธ์ด๊ฐ ๊ธธ์ด์ง๋ฏ๋ก ๋นํจ์จ์
3. ์ธ๋ถ ์คํ์ผ
/* style.css */
p {
color: red;
background-color: blue;
}
<!-- index.html -->
...
<head>
...
<link rel="stylesheet" href="style.css">
</head>
<body>
<p>Hello World</p>
</body>
...
- HTML๊ณผ CSS๋ฅผ ๋ถ๋ฆฌํ์ฌ ์ฝ๋์ ๊ฐ๋ ์ฑ๊ณผ ํจ์จ์ฑ์ ๋์ด๋ ๊ฐ์ฅ ๊ถ์ฅ๋๋ ๋ฐฉ์.
link
- ํ์ฌ ๋ฌธ์์ ์ธ๋ถ ๋ฆฌ์์ค์ ๊ด๊ณ๋ฅผ ๋ช ์ํ๋ ํ๊ทธ.
- ๋น ํ๊ทธ๋ก ์์ฑ๋ง์ ํฌํจ.
- head ํ๊ทธ ์์๋ง ์์นํ ์ ์๋ค.
- rel : ๊ด๊ณ, css ํ์ผ์ stylesheet
- href : ๊ฒฝ๋ก, ์ฐ๊ฒฐ ์ ์ฐธ์กฐํ ํ์ผ์ ์์น
4. ๋ค์ค ์คํ์ผ ์ํธ
<!-- ์ฌ๋ฌ ๊ฐ์ ์คํ์ผ์ํธ๋ฅผ ๋ถ๋ฌ์ฌ ์ ์๋ค. -->
...
<head>
...
<link rel="stylesheet" href="reset.css">
<link rel="stylesheet" href="font.css">
<link rel="stylesheet" href="layout.css">
<link rel="stylesheet" href="main.css">
</head>
<body>
<p>Hello world</p>
</body>
...
<!-- index.html -->
...
<head>
...
<link rel="stylesheet" href="style.css">
</head>
<body>
<p>Hello world</p>
</body>
...
/* style.css */
@import url("reset.css");
@import url("font.css");
@import url("layout.css");
@import url("main.css");
- css ํ์ผ ์์ css๋ฅผ ํฌํจํ ์ ์๋ค.
- ์ฑ๋ฅ ์ธก๋ฉด์์ css ํ์ฑ ์๊ฐ์ด ์ฆ๊ฐํ๋ฏ๋ก ๊ถ์ฅ๋์ง๋ ์๋๋ค.
- ๋ฒ๋ค๋ฌ๋ฅผ ์ฌ์ฉํ์ฌ css ํ์ผ์ ํฉ์น๊ฑฐ๋ ๋ถ๋ฆฌํ์ฌ ํ์ํ ์ํฉ์์๋ง ๋ก๋ฉํ ์ ์๋๋ก ์ต์ ํ ํ์.
'Dev. > CSS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[2023.03.03] 6. CSS ํ ์คํธ ์์ฑ (0) | 2023.03.03 |
---|---|
[2023.03.02] 5. CSS ๋จ์ ์ ๋ฆฌ (0) | 2023.03.02 |
[2023.03.02] 4. CSS ์์ (0) | 2023.03.02 |
[2023.03.02] 3. CSS ์ ํ์(๊ธฐ๋ณธ) (0) | 2023.03.02 |
[2023.03.02] 1. CSS ๊ธฐ๋ณธ (0) | 2023.03.02 |