【问题标题】:Nesting in emotion using css使用 css 在情感中嵌套
【发布时间】:2019-08-28 13:11:42
【问题描述】:

我有以下 JSX 结构。

<div css={content} style={{ minHeight: props.minHeight }}>
  <p css={description}>{props.description}</p>
</div>

现在我需要编写一个样式,当content 悬停时,它会改变description 的背景。如何使用 css 对象在情感中写出来。

我试过这样做。但它没有用。

const description = css({
  background: 'yellow'
})

const content = css({
  '&:hover': {
     [description]: {
        background: 'red',
     },
   },
})

提前致谢!

【问题讨论】:

  • 您可以在您的组件文件中导入 css 文件并将className 添加到您的描述标签中。它会一样工作。我不知道reactjs 中有css prop。你能告诉我文档链接吗?
  • 嘿 Kumar,感谢您的回答,但在这里不相关 :( 我使用 Emotion JS 进行样式设置。您可以阅读它。
  • 哦,我不知道。我需要学习。

标签: javascript css reactjs emotion


【解决方案1】:

在您的示例中,内容 css 对象没有提及“描述”是什么。你可以做的是像这样引用描述段落标签:

const description = css({
  background: 'yellow',
});

const content = css({
  '&:hover': {
    p: {
      background: 'red',
    },
  },
});

【讨论】:

    猜你喜欢
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    • 2020-05-06
    • 1970-01-01
    • 1970-01-01
    • 2020-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多