css - 反应原生绝对定位
问题描述
render() {
return (
<View style={{position: 'absolute'}}>
<View style={{top: 50, width:50, height: 50, backgroundColor:'green'}} ></View>
<View style={{top: 50, width:50, height: 50, backgroundColor:'blue'}} ></View>
<View style={{top: 50, width:50, height: 50, backgroundColor:'purple'}} ></View>
</View>
);
}
由于我使用的是绝对定位,因此我希望三个正方形彼此重叠放置在同一个位置。但我得到的是:
我可以在没有任何自动布局的情况下将三个方块准确定位在我要求它们的位置吗?
解决方案
是的,您可以,您必须使它们中的每一个都处于绝对位置。
<View>
<View style={{position: 'absolute', top: 50, width:50, height: 50, backgroundColor:'green'}} ></View>
<View style={{position: 'absolute', top: 50, width:50, height: 50, backgroundColor:'blue'}} ></View>
<View style={{position: 'absolute', top: 50, width:50, height: 50, backgroundColor:'purple'}} ></View>
</View>
推荐阅读
- javascript - 在常规 html 页面中使用 vue-multiselect.js
- wordpress - 如果 WordPress 类别为空,如何显示一行文本?
- r - order 函数如何打破 R 中的关系?
- xamarin.forms - Xamarin 跨平台蓝牙连接示例代码
- ruby - OpenSSL::X509::CertificateError:嵌套 asn1 错误
- angularjs - 使用Springboot从angularjs上传图像到FTP
- c# - 如何按键组合字典和列表
- python - 可以使用混合模式使用 Matplotlib 渲染在 Python 中绘制的点吗?
- jquery - 循环 jquery fadeIn() fadeOut() 出现问题
- ios - Swift 将数据转换为 UnsafeMutablePointer