【问题标题】:I want to add CSS for my child class in React Native我想在 React Native 中为我的子类添加 CSS
【发布时间】:2019-10-20 15:43:58
【问题描述】:

React Native 中需要答案。

<View>
  <View className="parent1">
    <Text>hello with green</Text>
  </View>
  <View>
    <Text>hello with default color</Text>
  </View>
</View>

现在我想添加 CSSText 有一个 parentclassnameparent1 React Native 中。

【问题讨论】:

  • 哪个子类,你能解释一下吗?
  • 文本组件,其父级为parent1
  • 你不能,react-native 在样式继承方面真的很有限。参考这篇文章:medium.com/@fullsour/…

标签: reactjs react-native css-selectors stylesheet styling


【解决方案1】:

如果您想为父类名为 parent1 的文本标签提供 CSS,请按照以下步骤操作

const stylesB = StyleSheet.create(
{

  Text:
  {
    color: '#ffffff',
  },
  p:
  {
    color: '#ffffff',
  },
  h3:
  {
    color: '#ffffff',
  },
  h1:{
    color: '#ffffff',
  }

});

<View>
  <View className="parent1" styles={stylesB}> //give styles as stylesB instead of giving stylesB.Text
    <Text>hello with green</Text>
  </View>
  <View>
    <Text>hello with default color</Text>
  </View>
</View>

对于类名为 parent1 且标签为 Text、p、h1 和 h3 的标签的子标签,此更改将显示为白色

【讨论】:

    猜你喜欢
    • 2021-03-01
    • 2021-11-19
    • 1970-01-01
    • 2020-03-16
    • 2018-11-04
    • 2022-01-18
    • 1970-01-01
    • 2021-06-17
    • 2019-06-12
    相关资源
    最近更新 更多