use*_*835 3 reactjs material-ui
我正在使用 React Material UI。符号&div:在组件的 css 样式中意味着什么。css样式如下。
contactWrapper: {
marginTop: theme.spacing(1),
'& div': {
display: 'flex',
},
},
Run Code Online (Sandbox Code Playgroud)
下面是使用该类的代码片段。
<div className={classes.contactWrapper}>
<span className={classes.contentLabel}> Contact:</span>
<div><Person className={classes.contactIcon} fontSize="small" /> {primaryContact.name}</div>
<div><Phone className={classes.contactIcon} fontSize="small" /> {primaryContact.phone}</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
它是 Material-ui 的Styled-Components API 的一部分。它是元素父级类名的引用。
和号 (&) 可用于引用主要组件。
与号 (&) 被我们为该样式组件生成的唯一类名所取代,从而可以轻松实现复杂的逻辑。
请参阅 Material-UI 的嵌套选择器演示。
const useStyles = makeStyles({
root: {
color: 'red',
'& p': { // p that is child of root classname
margin: 0,
color: 'green',
'& span': { // span that is child of parent p
color: 'blue',
},
},
},
});
export default function NestedStylesHook() {
const classes = useStyles();
return (
<div className={classes.root}>
This is red since it is inside the root.
<p>
This is green since it is inside the paragraph{' '}
<span>and this is blue since it is inside the span</span>
</p>
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1610 次 |
| 最近记录: |