【发布时间】:2021-11-29 22:47:27
【问题描述】:
我正在尝试使用left 和right 拉伸我的<View> 组件
我知道如何在 html 和 css 中做到这一点:
.testing{
background-color: orange;
position: absolute;
left: 100px;
right: 20px;
}
<div class="testing">
Hello there
</div>
但是如何在 react native 中实现相同的结果?
编辑
我试过了,但它不起作用:
export default function App() {
return (
<View style={styles.container}>
<View style={{ left: 100,right: 20,height:50,position: 'absolute', backgroundColor: 'orange'}}><Text>hello there</Text></View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
【问题讨论】:
-
只要你使用
css,方法都是一样的 -
@Viira 我厌倦了,但它不起作用,我已经对帖子进行了编辑,让我知道那段代码是否适合你
-
你为什么在
View里面使用View
标签: javascript html css react-native