You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update docs related to position to account for static (facebook#4235)
* Update docs related to position to account for static
* fix typo
* fix tsx lint
* fix format
* update RN version for linting to 0.74.1
* requested changes
* address nit
The `position` type of an element defines how it is positioned within its parent.
2580
+
The `position` type of an element defines how it is positioned relative to either itself, its parent, or its [containing block](./flexbox.md#the-containing-block).
2581
2581
2582
2582
-`relative` (**default value**) By default, an element is positioned relatively. This means an element is positioned according to the normal flow of the layout, and then offset relative to that position based on the values of `top`, `right`, `bottom`, and `left`. The offset does not affect the position of any sibling or parent elements.
2583
2583
2584
-
-`absolute` When positioned absolutely, an element doesn't take part in the normal layout flow. It is instead laid out independent of its siblings. The position is determined based on the `top`, `right`, `bottom`, and `left` values.
2584
+
-`absolute` When positioned absolutely, an element doesn't take part in the normal layout flow. It is instead laid out independent of its siblings. The position is determined based on the `top`, `right`, `bottom`, and `left` values. These values will posistion the element relative to its containing block.
2585
+
2586
+
-`static` When positioned statically, an element is positioned according to the normal flow of layout, and will ignore the `top`, `right`, `bottom`, and `left` values. This `position` will also cause the element to not form a containing block for absolute descendants, unless some other superceding style prop is present (e.g. `transform`). This allows `absolute` elements to be positioned to something that is not their parent. Note that **`static` is only available on the New Architecture**.
The containing block of an element is an ancestor element which controls its position and size.
2864
+
The way containing blocks work in React Native is very similar to [how they work on the web](https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block), with some simplifications due to the lack of some web features.
2865
+
2866
+
The `top`, `right`, `bottom`, and `left` values of an absolutely positioned element will be
2867
+
relative to its containing block.
2868
+
2869
+
Percentage lengths (e.g.: `width: '50%'` or `padding: '10%'`) applied to absolutely positioned elements will be calculated relatively to the size of its containing block. For example, if the containing block is 100 points wide, then `width: 50%` on an absolutely positioned element will cause it to be 50 points wide.
2870
+
2871
+
The following list will help you determine the containing block of any given element:
2872
+
2873
+
- If that element has a `position` type of `relative` or `static`, then its containing block is its parent.
2874
+
- If that element has a `position` type of `absolute`, then its containing block is the nearest ancestor in which one of the following is true:
2875
+
- It has a `position` type other than `static`
2876
+
- It has a `transform`
2877
+
2857
2878
## Going Deeper
2858
2879
2859
2880
Check out the interactive [yoga playground](https://www.yogalayout.dev/playground) that you can use to get a better understanding of flexbox.
Copy file name to clipboardExpand all lines: docs/layout-props.md
+10-7Lines changed: 10 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -923,17 +923,20 @@ Setting `paddingVertical` is like setting both of `paddingTop` and `paddingBotto
923
923
924
924
### `position`
925
925
926
-
`position` in React Native is similar to regular CSS, but everything is set to `relative` by default, so `absolute` positioning is always relative to the parent.
926
+
`position` in React Native is similar to [regular CSS](https://developer.mozilla.org/en-US/docs/Web/CSS/position), but everything is set to `relative` by default.
927
927
928
-
If you want to position a child using specific numbers of logical pixels relative to its parent, set the child to have `absolute` position.
928
+
`relative` will position an element according to the normal flow of the layout. Insets (`top`, `bottom`, `left`, `right`) will offset relative to this layout.
929
929
930
-
If you want to position a child relative to something that is not its parent, don't use styles for that. Use the component tree.
930
+
`absolute` takes the element out of the normal flow of the layout. Insets will offset relative to its [containing block](./flexbox.md#the-containing-block).
931
931
932
-
See https://github.com/facebook/yoga for more details on how `position` differs between React Native and CSS.
932
+
`static` will position an element according to the normal flow of the layout. Insets will have no effect.
933
+
`static` elements do not form a containing block for absolute descendants.
933
934
934
-
| Type | Required |
935
-
| ---------------------------- | -------- |
936
-
| enum('absolute', 'relative') | No |
935
+
For more information, see the [Layout with Flexbox docs](./flexbox.md#position). Also, [the Yoga documentation](https://www.yogalayout.dev/docs/styling/position) has more details on how `position` differs between React Native and CSS.
0 commit comments