How to achieve a centered grid layout with rows that are left-aligned? #854
Answered
by
marc2332
bonsairobo
asked this question in
Q&A
-
I'm trying to implement a grid layout, but it ends up aligned to the top-left corner: I would like it centered (horizontally) in the window instead. I've tried wrapping the grid in another element like so: rect {
width: "100%",
height: "100%",
direction: "vertical",
cross_align: "center",
...my grid element...
} But this doesn't seem to do anything. Here's the full code. |
Beta Was this translation helpful? Give feedback.
Answered by
marc2332
Sep 8, 2024
Replies: 1 comment 7 replies
-
hey! You were very close. You just need to remove the 100% width and 100% height from the second rect. This way the inner rect will not be expanded to its parent size and instead will be shrinked to its children size, and thus it will be centered. 🔴 rsx!(
rect {
width: "100%",
height: "100%",
direction: "vertical",
cross_align: "center",
rect {
width: "100%",
height: "100%",
// Children are rows.
direction: "vertical",
main_align: "start",
cross_align: "start", ✅ rsx!(
rect {
width: "100%",
height: "100%",
direction: "vertical",
cross_align: "center",
rect {
// Children are rows.
direction: "vertical", // You can remove this btw, it is the default value
main_align: "start", // Same for this
cross_align: "start", // Same for this |
Beta Was this translation helpful? Give feedback.
7 replies
Answer selected by
bonsairobo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hey! You were very close.
You just need to remove the 100% width and 100% height from the second rect. This way the inner rect will not be expanded to its parent size and instead will be shrinked to its children size, and thus it will be centered.
🔴
✅