ant-design / antd-style

css-in-js library with antd v5 token system
https://ant-design.github.io/antd-style/
MIT License
187 stars 29 forks source link

🧐[问题]有没有覆写现有类名样式的能力? #154

Closed ByYogi closed 2 weeks ago

ByYogi commented 2 weeks ago

像Emotion css 可以通过css属性覆写 div 里面的 p 标签和.cls2样式; 用 adtd-style 怎么做到这一点?

import { css } from '@emotion/react'
const color = 'white'
export default () => (
  <div
    css={css`
      padding: 32px;
      background-color: hotpink;
      font-size: 24px;
      border-radius: 4px;
      p {
        color: red;
      }
      .cls2{ color: blue;}
      &:hover {
        color: ${color};
      }
    `}
  >
  <p>Another</p>
  <div class="cls2">Another 2 </div>
    Hover to change color.
  </div>
)
ByYogi commented 2 weeks ago

可以通过 cx 函数实现以className实现样式覆写

import { cx,css } from 'antd-style';
const color = 'white'
export default () => (
  <div
    className={cx(css`
      padding: 32px;
      background-color: hotpink;
      font-size: 24px;
      border-radius: 4px;
      p {
        color: red;
      }
      .cls2{ color: blue;}
      &:hover {
        color: ${color};
      }
    `)}
  >
  <p>Another</p>
  <div class="cls2">Another 2 </div>
    Hover to change color.
  </div>
)