Global CSS
1. ๊ฐ์
๋๋ ์คํ์ผ ์ฝ๋์ ์ค๋ณต์ ํผํ๊ธฐ ์ํด ReactJS๋ก ๊ฐ๋ฐ์ ํ๋ ๊ฒฝ์ฐ styled-components๋ฅผ ์ฌ์ฉํ์ฌ ํ์ํ ์คํ์ผ์ ์ปดํฌ๋ํธ๋ฅผ ๋ง๋ค๊ณ ๋ง๋ ์คํ์ผ ์ปดํฌ๋ํธ๋ฅผ ํ์ํ ๊ณณ์ importํ์ฌ ์ฌ์ฉํ์๋ค.
ReactJS, VueJS๊ฐ ์๋ Html, Css, Javasrcipt๋ก๋ง ์น ๊ฐ๋ฐ์ ํ๊ฒ ๋๋ ๊ฒฝ์ฐ ์คํ์ผ๋ง์ ์ํด *.css(์คํ์ผ์ํธ)์ ๋ง๋ค๊ณ Link style๋ฐฉ๋ฒ์ ํตํด *.html๊ณผ *.css(์คํ์ผ์ํธ)๋ฅผ ์ฐ๊ฒฐํ๋ค.
๋ด๊ฐ ์๊ฐํ๋ ์์ ๊ฐ์ ๋ฐฉ๋ฒ์ ๋จ์ ์ ์๋์ ๊ฐ๋ค.
๋จ์
๊ฐ
*.htmlํ์ผ์ ๋ชจ๋ ๋ค๋ฅธ*.css(์คํ์ผ์ํธ)์ ์ฐ๊ฒฐํ๋ ๊ฒฝ์ฐ ๊ฐ์ ์คํ์ผ์ ์ฝ๋๋ฅผ ์ค๋ณตํ์ฌ ์์ฑํด์ผ ํ๋ ๊ฒฝ์ฐ๊ฐ ์๊ธธ ์ ์๋ค. ์๋ฅผ๋ค์ด ๊ฐ์ ์คํ์ผ์ ๋ฒํผ์ด ์๊ณ ์ด๋ฅผindex.html๊ณผprofile.html์์ ํ์ํ๋ค๋ฉดindex.css์profile.css์ ๊ฐ์ ์คํ์ผ์ ์ฝ๋๋ฅผ ์์ฑํด์ผ ํ๋ค. ์ด๋ฌํ ๋ฐฉ๋ฒ์ ๋ฒํผ ์คํ์ผ์ ์์ ์ ํด์ผํ๋ ๊ฒฝ์ฐ ํด๋น ์คํ์ผ์ ์ฝ๋๊ฐ ์ฌ์ฉ๋ ๋ชจ๋*.css(์คํ์ผ์ํธ)๋ฅผ ์ฐพ์ ํ๋ํ๋ ์์ ํด์ผ ํ๋ค.<!-- index.html --> ... <head> <link rel="stylesheet" href="index.css" /> </head> ...<!-- profile.html --> ... <head> <link rel="stylesheet" href="profile.css" /> </head> .../* index.css */ .button { color: red; }/* profile.css */ .button { color: red; }button.css,container.css,navbar.css๋ฑ ๊ฐ์ ๋งก๊ณ ์๋ ์ญํ ์*.css(์คํ์ผ์ํธ)์ ๋ง๋ค๋ฉด ์์ ๋จ์ ์ ํด์๊ฐ ๋๋ ๊ฐ*.html์์ ์์ฑํด์ผ ํ๋<link />ํ๊ทธ๊ฐ ๋ง์ด์ง๋ค. ๋ํ ์๋ก์ด ์คํ์ผ์ ๋ฌด์ธ๊ฐ๋ฅผ ์ถ๊ฐํ๊ฒ ๋๋ค๋ฉด ํด๋น ์คํ์ผ์ ์ฌ์ฉํ๋*.html์ ๋ชจ๋ ์ฐพ์ ์๋ก์ด<link />ํ๊ทธ๋ฅผ ์์ฑํด์ผ ํ๋ค./* button.css */ div { color: red; ...; }/* container.css */ div { color: red; ...; }/* navbar.css */ div { color: red; ...; }<!-- index.html --> ... <head> <link rel="stylesheet" href="button.css" /> <link rel="stylesheet" href="container.css" /> <link rel="stylesheet" href="navbar.css" /> </head> ...<!-- profile.html --> ... <head> <link rel="stylesheet" href="button.css" /> <link rel="stylesheet" href="container.css" /> <link rel="stylesheet" href="navbar.css" /> </head> ...
์ด๋ฌํ ๋จ์ ์ ํด๊ฒฐํ๊ณ ์ ๋ชจ๋
*.html์ ์ฐ๊ฒฐํ๋ ์๋ฅผ๋ค๋ฉดglobal.css๋ง๋ค๊ณ ์ฌ๊ธฐ์ ๋ชจ๋*.css(์คํ์ผ์ํธ)์@importํ๋ ๋ฐฉ๋ฒ์ ๋ํด ์๊ฐํ๋ค.
2. global.css
.cssํ์ผ ์ด๋ฆ์ styles, global ๋ฑ ์ํ๋ ์ด๋ฆ์ผ๋ก ์์ฑํด๋ ๋์ง๋ง ๋๋ ๋ชจ๋ *.html์์ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ ์ ์ญ์ด๋ผ๋ ์๋ฏธ๋ก global๋ฅผ ์ฌ์ฉํ๋ค.
css ํด๋๋ฅผ ๋ง๋ค๊ณ
global.css๋ฅผ ๋ง๋ ๋ค.
/* css/global.css */
body {
font-size: 16px;
color: rgba(20, 20, 20, 1);
}
...3. @import
@import CSS ๊ท์น์ ๋ค๋ฅธ ์คํ์ผ ์ํธ์์ ์คํ์ผ ๊ท์น์ ๊ฐ์ ธ์ฌ ๋ ์ฐ์
์ฌ์ฉ๋ฒ
@import url;
url: importํ ์์์ ์์น๋ฅผ ๋ํ๋ด๋ ๋ฌธ์์ด ๋๋ url
ํ์ํ
*.css(์คํ์ผ์ํธ)๋ฅผ ๋ง๋ค๊ณglobal.css์ importํ๋ค.
/* button.css */
div {
color: red;
...;
}/* container.css */
div {
color: red;
...;
}/* navbar.css */
div {
color: red;
...;
}/* css/global.css */
@import "button.css";
@import "container.css";
@import "navbar.css";
body {
font-size: 16px;
color: rgba(20, 20, 20, 1);
}
...์ดํ ๋ชจ๋
*.html์<link rel="stylesheet" href="css/global.css" />๋ฅผ ์ถ๊ฐํ๋ค.*.html์ ์์น์ ๋ฐ๋ฅธ ๊ฒฝ๋ก์์ฑ์ ํ์
<!-- index.html -->
...
<head>
<link rel="stylesheet" href="css/global.css" />
</head>
...4. Reset css
๋ชจ๋ ์น ๋ธ๋ผ์ฐ์ ๋ ๋ํดํธ ์คํ์ผ์ ๊ฐ์ง๊ณ ์์ด CSS๊ฐ ์์ด๋ ์๋ํจ. ํ์ง๋ง ์น ๋ธ๋ผ์ฐ์ ์ ๋ฐ๋ผ ๋ํดํธ ์คํ์ผ์ด ๋ค๋ฅด๊ณ ์ง์ํ๋ tag๋ style๋ ์ ๊ฐ๊ฐ์ด์ ์ฃผ์๊ฐ ํ์
CSS Reset๋ ๋ชจ๋ ํ๊ทธ์ ์ ์ฉ๋ ์์์ margin๊ณผ padding์ ์ ๊ฑฐํ๋ ๋ฐฉ์์ผ๋ก ์์๋์ด ๋ธ๋ผ์ฐ์ ์ ๊ธฐ๋ณธ์์์ ๋์์ธ์ ๋ชจ๋ ์์ ์๋ ๊ฒ์ผ๋ก ๋ฐ์ , ์ด๋ ๊ฒ ๋ชจ๋ 0์ผ๋ก ๋ง๋๋ ๋ฐฉ๋ฒ์ ํตํด์ ๋ธ๋ผ์ฐ์ ๋ค์ ์์์ ํ๋๋ก ํต์ผ
๊ฐ์ฅ ์ ๋ช ํ ๊ฒ์ ์๋ฆญ๋ง์ด์ด์ CSS Reset
Reset.css ์ ์ฉํ๊ธฐ
/* reset.css */
html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
display: block;
}
body {
line-height: 1;
}
ol,
ul {
list-style: none;
}
blockquote,
q {
quotes: none;
}
blockquote:before,
blockquote:after,
q:before,
q:after {
content: "";
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}/* css/global.css */
@import "button.css";
@import "container.css";
@import "navbar.css";
@import "reset.css";
body {
font-size: 16px;
color: rgba(20, 20, 20, 1);
}
...css reset์ ์ ๋ต์ ์๋ค๊ณ ํ๋ค. ๋ด๊ฐ ๋ง๋ค ์ฌ์ดํธ์ ํ์ํ reset๋ง ์ ์ฉํด์ ๋ง๋ค์ด๋ ๋๊ณ ์์ ๊ฐ์ด
reset.css๋ฅผ importํ ๋ค ์ถ๊ฐ๋ก reset์ด ํ์ํ ์คํ์ผ์global.css์ ์์ฑํด๋ ๋๋ค.
5. ๋ฒ๊ฑฐ๋ก์ด ์
global.css๋ฅผ ์ฌ์ฉํด์ ๋ฒ๊ฑฐ๋ก์ด ์ ์ด๋ผ๊ธฐ ๋ณด๋ค๋ html, css, javascript๋ก๋ง ์ด์ฉํด์ ์น์ ๋ง๋ค ๋์ ๋ฒ๊ฑฐ๋ก์ด ์ ์ ๋ง์ฝ ์ ๋๋ก ๋ ๊ธฐํ, ๋์์ธ ์์ด ๋ฐ๋ก ์ฝ๋๋ฅผ ์์ฑํ๋ฉด์ ์น์ ๋ง๋ค๋ค ๋ณด๋ฉด ์ค๊ฐ์ค๊ฐ์ class, id๋ฅผ ์์ , ์ถ๊ฐํ์ฌ ์์ฑํ๋ ๊ฒฝ์ฐ๊ฐ ๊ฐํน ์๊ธด๋ค.
๊ธฐํ, ๋์์ธ์ด ์๋๋ผ๋ *.html์ ์์ฑํ ๋ ๋ฏธ๋ฆฌ ๋์์ธ ๊น์ง ์๊ฐํ๋ฉฐ class, id๋ฅผ ๋ถ์ฌํ๋ค๋ฉด ์ด๋์ ๋๋ ๊ด์ฐฎ์์ง ๋ชฐ๋ผ๋ class, id๋ฅผ ๋์ค์ ๋์์ธ์ ํ ๋ ๋ง๋ค๊ฒ ๋๋ค๋ฉด ๋ชจ๋ *.html๋ฅผ ๋ค์ ์ด์ด์ ์ผ์ผํ class, id๋ฅผ ๋ถ์ฌํด์ผํ๋ ๋ฒ๊ฑฐ๋ก์์ด ์๊ธด๋ค.
๋ฌผ๋ก ReactJS๋ก ๊ฐ๋ฐ์ ํ๋ ๊ฒฝ์ฐ์๋ ์ฌ์ ๊ธฐํ, ๋์์ธ์ด ์๋ค๋ฉด ์ฝ๋์ ์ปดํฌ๋ํธ๋ ๋์ฅํ์ด ๋๋ค. ์ด๊ฑด ๊ฒฝํ๋ด... ํผ๊ทธ๋ง๋ก ๊ธฐํ ๋ฐ ๋์์ธํ๋ ๊ณต๋ถ, ์ฐ์ต๋ ํ์๐
์ฐธ๊ณ
poiemaweb 2-1 CSS ๊ธฐ๋ณธ๋ฌธ๋ฒ mdn @import 2022 CSS Reset ๋ค์ ์จ๋ณด๊ธฐ!
๐ 2022-07-11
Last updated