无法定位:在JSS中的伪选择器之前

Bra*_*ady 35 javascript styling reactjs

我试图在我的页面上定位元素的后伪选择器.我正在为这个项目尝试JSS,到目前为止我是一个巨大的粉丝,但仍然很新.我选择了JSS之后遇到了麻烦.这是否可能,因为我认为这是在阅读文档时.

这是我的标记:

<Link to="about" className={classes.link}>About</Link>

我的JSS看起来像这样:

link: {
    position: 'relative',
    fontFamily: fonts.family.primary
    '&:before': {
        content: ' ',
        position: 'absolute',
        bottom: 0,
        left: 50,
        width: '100%',
        height: '1rem',
        display: 'block',
        background:styles.colors.white
    }
}
Run Code Online (Sandbox Code Playgroud)

如果任何熟悉JSS的人都可以提供帮助,那就太棒了!

Nis*_*tha 76

你做的是对的.除了两件事:

1)语法错误:输入后您缺少逗号 fontFamily: fonts.family.primary

2)内容应该是用双引号括起来的字符串,而后者应该用单引号括起来.所以,一个空的内容将是content: '""',

所以试试以下内容:

link: {
    position: 'relative',
    fontFamily: fonts.family.primary,
    '&:before': {
        content: '""',
        position: 'absolute',
        bottom: 0,
        left: 50,
        width: '100%',
        height: '1rem',
        display: 'block',
        background:styles.colors.white
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 事实上,内容:'""使它成功. (11认同)
  • 因为我在尝试调试时多次偶然发现了这个问题,所以我想我会在这里补充一点,如果您的内容包含转义字符,则需要双重转义。例如:```内容:'"\\A"'``` (2认同)