【发布时间】:2021-05-06 19:47:43
【问题描述】:
谁能解释一下在这种情况下发生了什么:
在 HTML 中采用以下基本的 flex 布局:
<div style="background-color:grey; ">
<div style="padding:5px; background-color:red; display:flex">
<div style="flex:3; background-color:blue">
hi
</div>
<div style="flex:1; background-color:yellow">
do
</div>
</div>
</div>
正如预期的那样呈现 -
我想在 React Native 项目中使用类似的结构,它的呈现方式完全不同:
代码如下:
<View
style={{flexDirection: 'column', padding: 5, backgroundColor: 'red' }}>
<View style={{backgroundColor: 'blue', flex:1}}><Text>hi</Text></View>
<View style={{backgroundColor: 'yellow', flex:2}}><Text>do</Text></View>
</View>
但是,如果我将 flexDirection 切换为“行”,它会像您期望的“列”一样工作。即 -
今天下午我脑子里一片混乱!谁能解释一下这里发生了什么!?
【问题讨论】:
标签: css reactjs react-native flexbox