如何将边距添加到具有 flex-end 属性 的元素?
How do you add Margin to an Element with the flex-end property?
我正在尝试在我的 React 本机应用程序的屏幕右上角放置一个视图,并使用 alignSelf: 'flex-end'
和 position: absolute
完成了此操作。这行得通,但是我现在想用 margin: 15
在框周围添加边距,但这行不通。 View 在顶部有边距但在右边没有,大概是因为我对 flex-end
的使用将 View 放置在尽可能靠左的位置。我如何覆盖它并在视图周围添加边距?
只是不要使用 alignSelf: 'flex-end'
,因为您已经 position: 'absolute'
,请使用 top: 15
和 right: 15
使其位于右上角,距离为 15 像素:
<View style={{
flex: 0,
position: 'absolute',
top: 15,
right: 15
}}>...</View>
我正在尝试在我的 React 本机应用程序的屏幕右上角放置一个视图,并使用 alignSelf: 'flex-end'
和 position: absolute
完成了此操作。这行得通,但是我现在想用 margin: 15
在框周围添加边距,但这行不通。 View 在顶部有边距但在右边没有,大概是因为我对 flex-end
的使用将 View 放置在尽可能靠左的位置。我如何覆盖它并在视图周围添加边距?
只是不要使用 alignSelf: 'flex-end'
,因为您已经 position: 'absolute'
,请使用 top: 15
和 right: 15
使其位于右上角,距离为 15 像素:
<View style={{
flex: 0,
position: 'absolute',
top: 15,
right: 15
}}>...</View>