css - React Native View 不包含作为 subview 编写在该 View 中的文本组件?

标签 css react-native stylesheet

在代码中,您可以看到我在组件中创建了一个嵌套 View ,并为父 View 设置了边框颜色为“绿色”的样式,为 subview 设置了边框颜色为“黄色”的样式。 subview 包含一些文本。我的问题是为什么文本组件不在边框内,您可以在 image_2 中看到输出?

class Header extends React.Component{
     render(){
        return(
            <View style={styles.topView}>
                <View style={styles.header}>
                    <Text>MENUBAR</Text>
                    <Text>TITLE</Text>
                    <Text>HOME</Text>
                </View>
            </View>
        )
    }
}
const styles=StyleSheet.create({
    topView:{
        backgroundColor : '#87cefa',
        borderColor : 'green',
        borderWidth : 2
    },
    header : {
        flex:1,
        flexDirection : 'row',
        marginTop : '10%',
        backgroundColor : '#FFF000',
        borderColor : 'yellow',
        borderWidth : 3,
        alignSelf : 'stretch'
    }
})

代码输入图像:-

enter image description here

输出图像:-

enter image description here

最佳答案

您忘记将 flex:1 添加到此 View :

topView:{
    flex:1,
    backgroundColor : '#87cefa',
    borderColor : 'green',
    borderWidth : 2
},

希望对你有帮助。

关于css - React Native View 不包含作为 subview 编写在该 View 中的文本组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54038283/

相关文章:

css 弹出窗口禁用页面滚动

javascript - 将所有带有 vendor 前缀的变体分配给样式

html - 具有相同水平位置的div

css - IE7 THEAD 标签样式

jquery - 自定义 slider handle 捕捉到光标?

Windows 的 CSS 不同填充规则?

react-native - React native 应用程序在发布中保留旧版本

android - 无法在 react native 项目中扩展 Zip

ios - 如何在 iOS 上以 React Native 连接到真实设备上的本地主机?

html - 如何仅使用 HTML 和 CSS(可能是小型 JavaScript)制作多层下拉菜单