html - 如何在 React 和 Emotion 中将 2 个 css 变量附加到 JSX 元素

标签 html css reactjs jsx emotion

如何使用 Emotion 库将 style1 和 style2 附加到下面的 div?


const style1 = css`
  display: flex;
`

const style2 = css`
   width: 0;
`

const el= () => (
    <div css={style1}>
)

最佳答案

在 Emotion 中,您可以执行所谓的 composition 操作:

const style1 = css`
  display: flex;
`

const style2 = css`
   width: 0;
`

const el= () => (
    <div 
        css={css`
            ${style1};
            ${style2};
        `}
    >
)

关于html - 如何在 React 和 Emotion 中将 2 个 css 变量附加到 JSX 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64907959/

相关文章:

javascript - 向 html5 视频添加关闭按钮

javascript - 相对大小的 HTML Canvas

javascript - 单击时保持元素突出显示

html - 媒体查询转换问题

javascript - 如何验证 react 中的输入字段?

javascript - React Redux - 在辅助函数中访问现有商店

javascript - 如何隐藏div html?

html - Div 不会环绕 Firefox 中的内容

html - 带除法的边界半径

css - 语义UI,如何自定义菜单样式?