【发布时间】:2021-10-09 08:27:51
【问题描述】:
例如我正在尝试设置ListItem的样式
我可以找到很多使用 sx 的示例(都使用 Box 作为示例)
但是当我尝试以下类似的方法时,它不起作用
<ListItem button onClick={handleClick}
sx={{
root: {
//
}
}}
>
谢谢。
更新
这个尝试也不行
const MyListItem = styled(ListItem)({
root: {
width: "10%",
},
button: {
"&:hover": {
textDecoration: "none",
backgroundColor: "blue",
"@media (hover: none)": {
backgroundColor: "transparent",
},
},
},
});
<MyListItem button onClick={handleClick}>
//content
</MyListItem>
【问题讨论】:
-
尝试类而不是 sx
-
您应该使用
ListItemButton而不是在 v5 中将属性button传递给ListItem,因为该属性已被弃用。看看他们如何设计ListItemButtonhere。
标签: reactjs material-ui