Reactjs 如何重写已编译的类?
我试图将覆盖样式应用于已编译的类名。我的编译代码就像Reactjs 如何重写已编译的类?,reactjs,material-ui,jss,Reactjs,Material Ui,Jss,我试图将覆盖样式应用于已编译的类名。我的编译代码就像 我希望能够像这样针对特定的项目 constyles=()=>{MultiListItemText-root-262:{color:red;}}} 在香草CSS中,我只需执行.MultiListItemText-root-262:{color:red;} 我怎样才能在JSS中做同样的事情呢?你不能这样做。 类名“MuiListItemText-root-262”是动态的,id“262”不可靠,可能会更改 关于使用JSS覆盖,请参阅材料UI的官
我希望能够像这样针对特定的项目
constyles=()=>{MultiListItemText-root-262:{color:red;}}}
在香草CSS中,我只需执行.MultiListItemText-root-262:{color:red;}
我怎样才能在JSS中做同样的事情呢?你不能这样做。
类名“MuiListItemText-root-262”是动态的,id“262”不可靠,可能会更改
关于使用JSS覆盖,请参阅材料UI的官方文档:
根据您想要实现的变化程度,有几种技术可用
有关典型的“一次性”重写,请参见使用withStyles HOC的第一个示例代码
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
// We can inject some CSS into the DOM.
const styles = {
button: {
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
borderRadius: 3,
border: 0,
color: 'white',
height: 48,
padding: '0 30px',
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
},
};
function ClassNames(props) {
return (
<Button className={props.classes.button}>
{props.children ? props.children : 'class names'}
</Button>
);
}
ClassNames.propTypes = {
children: PropTypes.node,
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(ClassNames);
从“React”导入React;
从“道具类型”导入道具类型;
从“@material ui/core/styles”导入{withStyles}”;
从“@material ui/core/Button”导入按钮;
//我们可以向DOM中注入一些CSS。
常量样式={
按钮:{
背景:“线性梯度(45度,Fe6B30%,FF8E53 90%),
边界半径:3,
边界:0,
颜色:'白色',
身高:48,
填充:“0 30px”,
boxShadow:'0 3px 5px 2px rgba(255、105、135、3)',
},
};
函数类名称(道具){
返回(
{props.children?props.children:'classnames'}
);
}
ClassNames.propTypes={
子项:PropTypes.node,
类:PropTypes.object.isRequired,
};
导出默认样式(样式)(类名);
您可以通过为MuiListItemText定义样式对象来实现。例如,const muiListStyle={color:'red'},然后您可以内联使用它,或者您可以创建一个css文件并导入它