๊ฐํธํ๊ฒ ๋ฐ์ํ ํฌ๊ธฐ๋ฅผ ์ค์ ํด๋ด ์๋ค!
์ ์์ ์ฝ๋์ ๋๋ค.
index.js
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App";
import "./styles.css";
import { createGlobalStyle } from "styled-components";
const GlobalStyles = createGlobalStyle`
html {
font-size: 62.5%;
}
`;
const rootElement = document.getElementById("root");
const root = createRoot(rootElement);
root.render(
<StrictMode>
<GlobalStyles />
<App />
</StrictMode>
);
App.js
import "./styles.css";
import React from "react";
import Typography from "@mui/material/Typography";
import {
createTheme,
ThemeProvider,
responsiveFontSizes
} from "@mui/material/styles";
let theme = createTheme({
typography: {
fontFamily: "Noto Sans KR",
htmlFontSize: 10
}
});
/**
* (๋ฐ์ํ) ์ฌ์ฉ์๊ฐ ์ ์ํ theme์ ๊ธ๊ผด ํฌ๊ธฐ๊ฐ ํ๋ฉด ํฌ๊ธฐ์ ๋ง๊ฒ ๋ณํด์ผ ํจ.
* ๋ฐ๋ผ์, responsiveFontSizes๋ก theme๋ฅผ ๊ฐ์ธ์ค.
*/
theme = responsiveFontSizes(theme);
export default function App() {
return (
<ThemeProvider theme={theme}>
<div className="App">
<Typography variant="h1">๋ฐ์ํ</Typography>
</div>
</ThemeProvider>
);
}
00. rem
https://www.sitepoint.com/understanding-and-using-rem-units-in-css/
Rem in CSS: Understanding and Using rem Units - SitePoint
Adrian Sandu explains the purpose and advantages of rem units, demonstrating ways to use em and rem units in CSS layouts.
www.sitepoint.com
font size๋ฅผ ์ผ๊ด์ฑ ์๊ฒ ์ ํ๊ธฐ ์ํด์ , rem ๋จ์๋ฅผ ์จ์ค์ผ ํฉ๋๋ค. rem์ด๋ root ํฌ๊ธฐ์ ์์กดํ ๋จ์์ ๋๋ค. (root๋ html์ ๋๋ค.)
๊ทธ๋ฐ๋ฐ ํ์ฌ root์ defalutํฌ๊ธฐ๋ 16px์ ๋๋ค. ๊ทธ๋์ 10px์ rem์ผ๋ก ํํํ๊ธฐ ์ํด์ 16์ผ๋ก ๋๋ 0.625rem์ ์จ์ค์ผ ํฉ๋๋ค. ๊ทธ๋ฐ๋ฐ.. 16์ผ๋ก ๋๋๊ธฐ ๊ท์ฐฎ์์์. ์์ rem์ผ๋ก ํํํ๊ธฐ ํธํ๊ฒ ๋ฐ๊ฟ์ค์๋ค!๐ฅ
html์ defalut font-size์ ๋๋ค. ๊ทธ๋์ 16px ์ธ ๊ฒ์ด์ฃ .
html {
font-size: 100%;
}
๊ทธ๋ผ 10px์ ํํํ๊ธฐ ์ํด 0.625rem ๋์ , (๋น๊ต์ ์ฝ๊ฒ 10์ผ๋ก ๋๋) 1.0rem์ ์จ์ฃผ๊ธฐ ์ํด์ ์๋์ฒ๋ผ ์ค์ ํด์ค๋๋ค.
html {
font-size: 62.5%; /* 62.5% of 16px = 10px */
}
index.js์ createGlobalStyle์ผ๋ก ์ ์ฉํ ๋ชจ์ต์ ๋๋ค.
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App";
import "./styles.css";
import { createGlobalStyle } from "styled-components";
const GlobalStyles = createGlobalStyle`
html {
font-size: 62.5%;
}
`;
const rootElement = document.getElementById("root");
const root = createRoot(rootElement);
root.render(
<StrictMode>
<GlobalStyles />
<App />
</StrictMode>
);
01. theme
https://mui.com/material-ui/customization/typography/
Typography - Material UI
The theme provides a set of type sizes that work well together, and also with the layout grid.
mui.com
htmlFontSize๋ฅผ 10์ผ๋ก ์ค์ ํฉ๋๋ค.
const theme = createTheme({
typography: {
// Tell MUI what's the font-size on the html element is.
htmlFontSize: 10,
},
});
๊ทธ ํ, ์ฌ์ฉ์๊ฐ ์ ์ํ theme ๊ธ๊ผด ํฌ๊ธฐ๊ฐ ๋ฐ์ํ์ด ์ ์ฉ๋๋๋ก responsiveFontSizes๋ก theme๋ฅผ ๊ฐ์ธ์ค๋๋ค.
/**
* (๋ฐ์ํ) ์ฌ์ฉ์๊ฐ ์ ์ํ theme์ ๊ธ๊ผด ํฌ๊ธฐ๊ฐ ํ๋ฉด ํฌ๊ธฐ์ ๋ง๊ฒ ๋ณํด์ผ ํจ.
* ๋ฐ๋ผ์, responsiveFontSizes๋ก theme๋ฅผ ๊ฐ์ธ์ค.
*/
theme = responsiveFontSizes(theme);
๋ง์ง๋ง์ผ๋ก theme๋ฅผ ์ธ์๋ก ๋๊ฒจ์ค ThemeProvider๋ก ์ปดํฌ๋ํธ๋ฅผ ๊ฐ์ธ์ค๋๋ค.
https://avoc-o-d.tistory.com/45
[Material Design] Material-UI(MUI)๋ก react & styled component ์ฌ์ฉํ๊ธฐ <๊ธฐ๋ณธ theme๋ฅผ ์ปค์คํฐ๋ง์ด์งํ๊ธฐ>
https://mui.com/material-ui/customization/theming/ Theming - Material UI Customize MUI with your theme. You can change the colors, the typography and much more. mui.com theme๋ฅผ ์ ์ํ๋ฉด, ์ปดํฌ๋ํธ๋ฅผ..
avoc-o-d.tistory.com
02. ์ ์ฉ
width, height ๋ฑ๋ฑ ํฌ๊ธฐ๋ฅผ ์ ํด์ค์ผํ๋ ๋จ์๋ค์ rem์ผ๋ก ์ฌ์ฉํด์ค๋๋ค.
์ ์์๋ height๊ฐ 7.2rem(72px)์ ์ ์ฉํ ๋ฒํผ์ ๋๋ค.
import "./styles.css";
import React from "react";
import Button from "@mui/material/Button";
import {
createTheme,
ThemeProvider,
responsiveFontSizes
} from "@mui/material/styles";
let theme = createTheme({
typography: {
fontFamily: "Noto Sans KR",
htmlFontSize: 10
}
});
/**
* (๋ฐ์ํ) ์ฌ์ฉ์๊ฐ ์ ์ํ theme์ ๊ธ๊ผด ํฌ๊ธฐ๊ฐ ํ๋ฉด ํฌ๊ธฐ์ ๋ง๊ฒ ๋ณํด์ผ ํจ.
* ๋ฐ๋ผ์, responsiveFontSizes๋ก theme๋ฅผ ๊ฐ์ธ์ค.
*/
theme = responsiveFontSizes(theme);
export default function App() {
return (
<ThemeProvider theme={theme}>
<div className="App">
<Button variant="contained" sx={{ height: "7.2rem" }}>
๋ฐ์ํ ๋ฒํผ
</Button>
</div>
</ThemeProvider>
);
}
๊ทธ๋ผ ์ด์ ์ด๋ค ์ปดํฌ๋ํธ๋ฅผ ์ฐ๋ ๋ฉํ ๋ฆฌ์ผ ๋์์ธ์์ ์ ๊ณตํด์ฃผ๋ ์ปดํฌ๋ํธ์๋ ๋ฐ์ํ์ด ์ ์ฉ๋ ๊ฒ์ ๋๋ค..!!!!