Dav*_*vid 8 reactjs material-ui
例如我正在尝试设计风格ListItem
我可以找到很多使用的示例sx(全部使用 Box 作为示例),但是当我尝试如下所示的操作时,它不起作用
<ListItem button onClick={handleClick}
sx={{
root: {
//
}
}}
>
Run Code Online (Sandbox Code Playgroud)
谢谢。
更新
这个尝试也行不通
const MyListItem = styled(ListItem)({
root: {
width: "10%",
},
button: {
"&:hover": {
textDecoration: "none",
backgroundColor: "blue",
"@media (hover: none)": {
backgroundColor: "transparent",
},
},
},
});
Run Code Online (Sandbox Code Playgroud)
<MyListItem button onClick={handleClick}>
//content
</MyListItem>
Run Code Online (Sandbox Code Playgroud)
Nea*_*arl 13
sx这是使用prop设计根组件的方式
<ListItem
sx={{
// your root styles
"&": {
// your root styles but with higher CSS specificity
},
"&.MuiListItem-root": {
// your root styles but with even higher CSS specificity
}
}}
/>
Run Code Online (Sandbox Code Playgroud)
它类似于 v4 中的旧方法:
const useStyles = makeStyles({
root: {
// your root styles
"&": {
// your root styles but with higher CSS specificity
},
"&.MuiListItem-root": {
// your root styles but with even higher CSS specificity
}
}
});
Run Code Online (Sandbox Code Playgroud)
<ListItem className={classes.root}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9815 次 |
| 最近记录: |