【问题标题】:Change margin from child component from parent component从父组件更改子组件的边距
【发布时间】:2018-08-03 10:12:20
【问题描述】:

我正在学习 react-native,我正在使用 styled-components。
在 react-native 中,我知道可以制作具有某种样式的组件,并且父级可以添加一些额外的样式,如下所示:
父.js

<CardSection style={{ flexDirection: 'column' }}>

Child.js

<View style={[styles.containerStyle, props.style]} >

然后 flexDirection 会自动添加到该元素的容器样式中。
在样式组件中是否有类似的事情?

【问题讨论】:

    标签: react-native react-redux styled-components


    【解决方案1】:

    您可以扩展样式以重用代码。但这只是用于继承,您不能使用 div 或类似的东西扩展按钮。

    这里有更多信息: https://www.styled-components.com/docs/basics#extending-styles

    我要做的是尝试正常的 css 继承,因为这也适用于 SC。在此处阅读更多信息https://developer.mozilla.org/en-US/docs/Learn/CSS/Introduction_to_CSS/Cascade_and_inheritance

    【讨论】:

      猜你喜欢
      • 2019-06-05
      • 2017-10-22
      • 1970-01-01
      • 2016-12-21
      • 2021-04-25
      • 2016-12-26
      • 1970-01-01
      • 2023-02-20
      相关资源
      最近更新 更多