본문 바로가기

ReactJS

ReactJS (3) Global Style

React를 쓰다 보면 global style을 적용시켜야 될 때가 있는데 그때 styled-components에서 createGlobalStyle을 쓰면 된다

 

예) CSS Reset

const GlobalStyle = createGlobalStyle`
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;
}



`;

이런 식으로 createGlobalStyle을 import 하고 적용시키는 방법은 App component와 같은 선상에 두는 것이다 

 

예)

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
  <ThemeProvider theme={darkTheme}>
    <GlobalStyle />
    <App />
  </ThemeProvider>
);

'ReactJS' 카테고리의 다른 글

ReactJS (5) Router  (0) 2023.03.04
ReactJS (0) ReactJS 프로젝트 시작하기  (0) 2023.03.04
ReactJS (4) Theme Provider  (0) 2023.03.04
ReactJS (2) Styled Component  (0) 2023.03.04
ReactJS (1) JSX  (0) 2023.03.04