โจ Overriding nested component styles
https://mui.com/material-ui/customization/how-to-customize/
How to customize - Material UI
Learn how to customize Material UI components by taking advantage of different strategies for specific use cases.
mui.com
๐ก์ค์ฒฉ๋ ์ปดํฌ๋ํธ style์ override ํ๊ธฐ ์ํด์
์ปดํฌ๋ํธ์ css ํด๋์ค ์ด๋ฆ์ ์ฌ์ฉํด์ CSS selector๋ฅผ ์์ฑ ํ, ์ปค์คํ ํด์ฃผ๋ฉด ๋ฉ๋๋ค.
์๋ฅผ ๋ค์ด,
ํด๋น ์ปดํฌ๋ํธ์ ํด๋์ค ์ด๋ฆ์ด MuiSlider-thumb ์ผ ๋, & .MuiSlider-thumb ๋ผ๋ CSS selector๋ก ์ปค์คํ ํด์ค๋๋ค.
<Slider
defaultValue={30}
sx={{
width: 300,
color: 'success.main',
'& .MuiSlider-thumb': {
borderRadius: '1px',
},
}}
/>
CardContent padding customize
์๋์ ๊ฐ์ ์ปดํฌ๋ํธ๋ฅผ ์์ฑํ์ต๋๋ค.
import * as React from "react";
import { Card, CardContent, Typography, Box } from "@mui/material";
export default function App() {
return (
<Card elevation={5}>
<CardContent>
<Box>
<Typography variant="body1">padding</Typography>
</Box>
</CardContent>
</Card>
);
}
์! ๊ทธ๋ฐ๋ฐ, ์ ๋ padding-top, padding-bottom ์ ํฌ๊ธฐ๊ฐ ๊ฐ์ผ๋ฉด ์ข์ ๊ฒ ๊ฐ์์!
padding-bottom ๋ฅผ padding-top๊ณผ ๊ฐ๊ฒ sx ์ธ์๋ก ๋๊ฒจ ๋ณด๊ฒ ์ต๋๋ค.๐คญ
<CardContent sx={{ paddingBottom: "1.6rem" }}>
๊ทธ์น๋ง ๊ทธ๋๋ก๋ค์,,
๐ก last child selector ์ style์ด padding-bottom ์ด 24px๋ก ๊ณ ์ ๋์ด ์๊ธฐ ๋๋ฌธ์ ๋๋ค.
override ๋ก ์ด๋ฅผ ์ปค์คํฐ๋ง์ด์ง ํด์ฃผ๊ฒ ์ต๋๋ค.
last-child customize
๐ &:last-child ์์ฑ์ ์ด์ฉํฉ๋๋ค.
๐ paddingBottom ๋ pb ์ ๋์ผํฉ๋๋ค.
<CardContent sx={{ "&:last-child": { paddingBottom: "1.6rem" } }}>
<CardContent sx={{ "&:last-child": { pb: "1.6rem" } }}>
๊ฒฐ๊ณผ๋?! ์ปค์คํ ๋์์ต๋๋ค~~!!!๐๐
import * as React from "react";
import { Card, CardContent, Typography, Box } from "@mui/material";
export default function App() {
return (
<Card elevation={5}>
<CardContent sx={{ "&:last-child": { paddingBottom: "1.6rem" } }}>
<Box>
<Typography variant="body1">padding</Typography>
</Box>
</CardContent>
</Card>
);
}