css-selectors - How to group CSS selectors with Material-UI?
问题描述
I am wondering if there is a way to group CSS selectors with Material-UI to avoid repetition, from something like this:
const useStyles = makeStyles(() => ({
root: {
backgroundColor: '#000000',
color: '#ffffff',
'&::before': {
content: '""',
position: 'absolute',
borderTop: '1px solid white',
},
'&::after': {
content: '""',
position: 'absolute',
borderTop: '1px solid white',
}
},
}));
To something that would look more or less like this?
const useStyles = makeStyles(() => ({
root: {
backgroundColor: '#000000',
color: '#ffffff',
'&::before',
'&::after': {
content: '""',
position: 'absolute',
borderTop: '1px solid white',
}
},
}));
Thanks for your help!
解决方案
我实际上找到了解决方案,就像在 2 个 CSS 选择器之间使用逗号一样简单:
const useStyles = makeStyles(() => ({
root: {
backgroundColor: '#000000',
color: '#ffffff',
'&::before, &::after': {
content: '""',
position: 'absolute',
borderTop: '1px solid white',
}
},
}));
推荐阅读
- package - 如何卸载 jupyterlab 的风筝?
- scikit-learn - 如何用不同的方法分别矢量化数据框列?
- java - GET /me 没有映射
- flutter - 更新到 Flutter 2.0 时出现的 Flutter 版本问题
- python - kmode集群中点和质心之间的差异
- python-3.x - 如何将输入参数传递给 Graphene 中的嵌套对象?
- python - 将从 python 字典中提取的信息写入文件
- php - 将文件读入字符串时如何扩展文本文件中的变量?
- typescript - 键入 Object.values(users).forEach
- python - 如何在 Python 中检测屏幕像素的颜色