Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between alignItems and alignSelf in React Native?

I am trying to understand the FlexBox implementation on React Native and find it very unfortunate that Facebook's documentation doesn't provide any info at all on what the individual properties mean. They only name the ones that they have implemented without further documentation...

I love the Flexbox in 5 tutorial, it does an amazing job in explaining the most important FlexBox properties. However, there is no mention of the alignSelf property there and I also didn't find documentation about this one elsewhere...

Can someone explain (maybe even demonstrate visually) what the difference between the two is? I also appreciate links to any resources that explain the React Native FlexBox properties in more detail and provide some guidance in using them.

like image 472
nburk Avatar asked Apr 12 '16 15:04

nburk


People also ask

What is the difference between align-content and align-items?

The align-content property determines how flex lines are aligned along the cross-axis while the align-items property determines how flex items are aligned within a flex line and along the cross-axis.

What does flex 1 mean React Native?

Normally you will use flex: 1 , which tells a component to fill all available space, shared evenly amongst other components with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

What is flex wrap in React Native?

Flex Wrap​ The flexWrap property is set on containers and it controls what happens when children overflow the size of the container along the main axis. By default, children are forced into a single line (which can shrink elements).

How do you use justify-content in React Native?

Syntax: justify-content: flex-start|flex-end|center|space-between| space-around|space-evenly; Property Values: flex-start: It is the default value of justifyContent.


2 Answers

alignItems and alignSelf have the same functionality per se. The only difference being, alignItems applies the alignment on to it's children while alignSelf applies the alignment to itself. This is useful when you want to change the alignment of one child.

Here is an illustration from https://css-tricks.com/snippets/css/a-guide-to-flexbox/

The above happens when the container has a style alignItems:'flex-start'

enter image description here

This happens when the container has the style alignItems:'flex-start' and the third child has the style alignSelf:'flex-end

like image 183
Nishanth Shankar Avatar answered Sep 26 '22 22:09

Nishanth Shankar


alignSelf can override the alignItems value for specific items.

like image 27
joemaddalone Avatar answered Sep 26 '22 22:09

joemaddalone