【发布时间】:2019-08-13 07:46:32
【问题描述】:
我在 React Native 中进行了很多编程,我正在尝试 React js(仅限 Web),但我不知道如何制作一个简单的 View,让所有屏幕都可以开始使用所有组件。
让我解释一下:
在 React Native 中,我使用 flex 处理视图尺寸,如下所示:
<View style={{ flex: 1 }}>
<View style={{ flex: 0.5, backgroundColor: 'blue' }}>
<Text>I'm a blue 50% screen View!</Text>
</View>
<View style={{ flex: 0.5, backgroundColor: 'yellow' }}>
<Text>I'm a yellow 50% screen View!</Text>
</View>
</View>
但在 React JS 中,我必须使用无法识别 flex 的 div 标签。 我的意思是,我不能这样做:
<div style={{ flex: 1 }}>
<div style={{ flex: 0.5, backgroundColor: 'blue' }}>
<p>I'm a blue 50% screen View!</p>
</div>
<div style={{ flex: 0.5, backgroundColor: 'yellow' }}>
<p>I'm a yellow 50% screen View!</p>
</div>
</div>
我必须如何在 React js 中为 div 使用这些样式来获得百分比结果?
【问题讨论】:
-
什么意思,“我必须使用无法识别 flex 的 div 标签。” ?
-
我的意思是我制作了一个样式为 flex 1 的 div 并且没有任何反应,而不是如果我在 react native 中做的话
-
你仍然可以在你的CSS中使用
div { flex: 1 }。这是flex-grow: 1;flex-shrink: 1; flex-basis: 0%; }的简写 -
我做了,但没有任何反应,div 没有填满整个屏幕。
标签: javascript css reactjs react-native flexbox