Reset CSS 사용방법

Reset CSS 개념


각 웹브라우저마다 기본적인 스타일(default styles)을 가지고 있다. 그래서, 내가 의도한 css 코드가 각 브라우저마다 다르게 나올 수 있다. 각 브라우저가 지원하는 tag나 style이 다를 수 있다. 따라서, 프로젝트를 시작할 때, 모든 브라우저가 동일한 스타일을 갖도록 CSS를 초기화할 필요가 있다. CSS를 초기화하는 것을 Reset CSS라고 한다.


Reset CSS를 사용하는 방법


아래 둘중에 하나의 방법으로 Reset CSS를 하면된다.

[1] Eric Meyer’s reset

다음의 css 코드를 CSS 파일 최상단에 작성하고 시작한다.

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/

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;
}

[2] normalize.css

npm 또는 yarn을 이용해서 normalize.css를 설치한다.

참고: normalize.css


React에서 Reset CSS 사용하는 방법


[1] normalize.css 설치

1
2
3
4
5
// yarn
yarn add normalize.css

// npm
npm install normalize.css

[2] index.js에 import

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// index.js

import React from "react";
import ReactDOM from "react-dom";
// import "./index.css";

import "normalize.css"; // Reset CSS

import App from "./App";
import * as serviceWorker from "./serviceWorker";

ReactDOM.render(<App />, document.getElementById("root"));

serviceWorker.unregister();