Jen*_*fer 3 css reactjs styled-components
我用 styled-component 包装了现有组件,但我发现必须声明!important覆盖该组件的现有样式很烦人,例如
import { Row, Col, Card, Typography } from 'antd'
const { Title } = Typography
const StyledTitle = styled(Title)`
text-align: center;
margin: 50px 0 20px 0 !important;
font-weight: normal !important;
`
Run Code Online (Sandbox Code Playgroud)
很难看出哪个属性必须使用重要,我在保存文件后通过视觉变化检测到它,这太烦人了,有什么解决方案?
They recommend adding ampersands
const StyledTitle = styled(Title)`
&&& {
text-align: center;
margin: 50px 0 20px 0;
font-weight: normal;
}
`
Run Code Online (Sandbox Code Playgroud)
https://styled-components.com/docs/faqs#how-can-i-override-styles-with-higher-specificity
| 归档时间: |
|
| 查看次数: |
1718 次 |
| 最近记录: |