React Native 样式表未按预期工作

问题描述 投票:0回答:2

这是代码片段

import { SafeAreaView, StyleSheet, Text, View } from 'react-native'
import React from 'react'

export default function Flatcards() {
  return (
    <SafeAreaView>
    <View>
      <Text style={styles.headingText}>Flatcards</Text>
        <View style= {styles.container}>
            <View style = {[styles.card, styles.redCard]}>
                <Text>RED</Text>
            </View>
        </View>
    </View>
    </SafeAreaView>
  )
}

const styles = StyleSheet.create({
    headingText : {
        fontSize: 20,
        fontWeight:'bold',
    },
    container:{
  
    },
    card: {
        height: 100,
        width: 100
    },
    redCard:{
        backgroundColor: 'EF5354',
    }
}
)

不知何故,在输出中,headingText 按预期工作,但 styles.card 和 styles.redCard 不起作用。它只打印普通的“RED”。这里可能出了什么问题?

reactjs react-native stylesheet
2个回答
1
投票

将flex:1的样式,宽度,高度赋予“styles.container”的样式

如果不起作用,请给我覆盖它的标签的样式


0
投票

背景颜色中缺少#。背景颜色应该是“#EF5354”而不是“EF5354”。

© www.soinside.com 2019 - 2024. All rights reserved.