티스토리 뷰

프로그래밍/Frontend

[React] reset.css 적용 방법

돔돔이부하 2021. 5. 14. 15:38
728x90
반응형
npm install styled-reset

우선 styled-reset 을 설치해줍니다.

 

styled-components는 local로 돌아가기 때문에 global 한 css 를 만들기 위해서 createGlobalStyle 을 styled-components 로부터 import 해줍니다. 그리고 방금 설치한 styled-reset 도 import 해줍니다.

import { createGlobalStyle } from 'styled-components';
import reset from 'styled-reset';

 

그리고 GlobalStyles 라는 컴포넌트를 만들어줍니다.

const GlobalStyles = createGlobalStyle`
    ${reset};
`;

 

참고로 ${reset} 내용을 출력해보면 아래와 같이 나옵니다.

$ /* http://meyerweb.com/eric/tools/css/reset/ v5.0.1 | 20191019 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, menu, 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, main, 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, main, menu, nav, section { display: block; } /* HTML5 hidden-attribute fix for newer browsers */ *[hidden] { display: none; } body { line-height: 1; } menu, 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; }

 

이제 위에서 만든 GlobalStyles 라는 컴포넌트를 사용해주면 끝입니다.

(아래 파일은 App.js 이고 index.js에서는 App.js 를 웹페이지에 렌더링해주고 있습니다.)

class App extends Component {
    render() {
        return (
            <>
                ${reset}
                <GlobalStyles />
                <StyledComponents />
            </>
        );
    }
}

export default App;

 

 

- 끝 -

728x90
반응형
댓글