有誰知道如何在不使用 JS 的情況下覆寫 Material UI 中的顏色?有沒有辦法只使用 CSS 覆寫顏色?
uj5u.com熱心網友回復:
是的。你絕對可以做到這一點,并且有多種方法可以做到這一點。一切都在這里的官方檔案中進行了解釋
最簡單的方法是sx在組件中使用 prop,但如果您愿意,也可以只使用 css。
uj5u.com熱心網友回復:
您可以使用styled來覆寫樣式。https://mui.com/system/styled/#main-content
import Box from '@mui/material/Box';
import { styled } from '@mui/system';
styled(Box)`
height: 100px;
width: 100px;
background-color: red;
`
uj5u.com熱心網友回復:
import * as React from 'react';
import { styled } from '@mui/system';
const MyComponent = styled('div')({
color: 'darkslategray',
backgroundColor: 'aliceblue',
padding: 8,
borderRadius: 4,
});
export default function BasicUsage() {
return <MyComponent>Styled div</MyComponent>;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/416923.html
標籤:
