4

我现在一直在兜圈子,试图了解正在发生的事情。我正在使用带有 Tailwind 的故事书制作设计库。我似乎无法让 :before 伪类工作。无论我将它放在样式中的哪个位置,它都不会被渲染。

一个例子是我正在尝试制作一个使用 react-slick 的组件,并且想要设置导航样式:

'& .slick-dots': {
  bottom: -30,
  display: 'block',
  left: 4,
  listStyle: 'none',
  margin: 0,
  padding: 0,
  position: 'absolute',
  textAlign: 'center',
  width: '100%',

  '& li': {
    cursor: 'pointer',
    display: 'inline-block',
    height: 20,
    margin: '0 5px',
    padding: 0,
    position: 'relative',
    width: 20,

     '& button': {
       border: 0,
       background: 'transparent',
       display: 'block',
       height: 20,
       width: 20,
       outline: 'none',
       lineHeight: 0,
       fontSize: 0,
       color: 'transparent',
       padding: 5,
       cursor: 'pointer',

       '&:before': {
        position: 'absolute',
        top: 0,
        left: 0,
        content: '',
        width: 20,
        height: 20,
        fontFamily: 'sans-serif',
        fontSize: 20,
        lineHeight: 20,
        textAlign: 'center',
        color: '#000000',
        opacity: 0.75,
        display: 'inline-block',
      },
    },
  },
},
4

2 回答 2

5

发现了问题。:before 伪类不会呈现,除非有内容,但在 js 中的 css 的情况下,内容需要看起来像这样content: '"text"',而不是content: 'text',

于 2020-05-27T08:42:55.237 回答
0

要让 :before 类工作,您必须使用 tailwindcss-pseudo-elements 包来自定义您的伪元素。检查下面的文档

https://www.npmjs.com/package/tailwindcss-pseudo-elements

于 2021-05-12T11:54:51.320 回答