Reputation: 493
In react native I cannot use something like float:left
or float:right
so I want to align items extreme left and right how can I do that? I have used absolute position on parent View but inside that View flexdirection and justify content space between is not working why so? Does flexbox and absolute positioning doesn't work together?
Code:
<View style={styles.cardContent}>
<View style={{maxWidth: 175}}>
<Text
style={{
fontSize: 16,
fontWeight: '700',
padding: 10,
color: 'white',
}}>
{hotelName}
</Text>
</View>
<View style={{flexDirection: 'column', marginLeft: 75}}>
<Text
style={{
fontSize: 20,
fontWeight: '700',
padding: 5,
textAlign: 'right',
color: 'white',
}}>
₹ {newRate}
</Text>
<Text
style={{
fontSize: 16,
fontWeight: '700',
textAlign: 'right',
color: 'white',
textDecorationLine: 'line-through',
textDecorationStyle: 'solid',
}}>
₹ {oldRate}
</Text>
</View>
</View>
CSS:
cardContent: {
position: 'absolute',
bottom: 0,
flexDirection: 'row',
justifyContent: 'space-between',
},
For cardContent I cannot remove position absolute and bottom 0 property because I want to fix the card at bottom of the screen.
In below screenshot you can see that hotel name is present on extreme left but newRate and oldRate is not going in extreme right even after using flexDirection: 'row'
and justify content: space between
Screenshot:
Upvotes: 2
Views: 10272
Reputation: 1
I would just add width: Dimensions.get('window').width
to the cardContent
style instead of width: 100%
.
Since 100%
means that you want this element to fits 100% of its parent width and Dimensions.get('window').width
means that you want the width of the viewport (device).
Upvotes: 0
Reputation: 576
You can try this
cardContent: {
position: 'absolute',
bottom: 0,
flexDirection: 'row',
justifyContent: 'space-between',
backgroundColor:'red',
width:'100%' // add width
},
Upvotes: 6