我在很多Material UI代码中看到他们在React的样式组件中使用伪选择器。我想自己试一试,但是我做不到。我不确定我哪里做错了,或者这是否可能。
我正在尝试创建一些CSS来将此元素与固定标题进行偏移。
import React from 'react';
import { createStyles, WithStyles, withStyles, Typography } from '@material-ui/core';
import { TypographyProps } from '@material-ui/core/Typography';
import GithubSlugger from 'github-slugger';
import Link from './link';
const styles = () =>
createStyles({
h: {
'&::before': {
content: 'some content',
display: 'block',
height: 60,
marginTop: -60
}
}
});
interface Props extends WithStyles<typeof styles>, TypographyProps {
children: string;
}
const AutolinkHeader = ({ classes, children, variant }: Props) => {
// I have to call new slugger here otherwise on a re-render it will append a 1
const slug = new GithubSlugger().slug(children);
return (
<Link to={`#${slug}`}>
<Typography classes={{ root: classes.h }} id={slug} variant={variant} children={children} />
</Link>
);
};
export default withStyles(styles)(AutolinkHeader);
content: '""'
。 - Eran Goldincontent
属性之前添加此行:/* eslint quotes: [2, "double", "avoid-escape"] */
,因为这将允许字符串使用单引号或双引号,只要字符串包含一个必须进行转义的引号即可。 - Christopher