首页 > 解决方案 > 如何在 React & Emotion 中将 2 个 css 变量附加到 JSX 元素

问题描述

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


const style1 = css`
  display: flex;
`

const style2 = css`
   width: 0;
`

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

标签: htmlcssreactjsjsxemotion

解决方案


在 Emotion 中,您可以执行所谓的组合

const style1 = css`
  display: flex;
`

const style2 = css`
   width: 0;
`

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

推荐阅读