Vertical
vertical
lets you lay things out vertically with Flexbox.
Create vertical layouts with Flexbox
There are many advantages of using display:flex
over display:block
.
<div class="vertical"> <div>One</div> <div>Two</div> <div>Three</div></div>
Adjust the space between items easily
With vertical
, you can adjust space between items with gap
. It’s more intuitive than margin
because there’s no need to deal with “margin collapse”.
<div class="vertical gap-8"> <div>One</div> <div>Two</div> <div>Three</div></div>
Easily align items to the left, center, or right.
You can use align-items
to shift all items to the left, center, or right.
Easily align individual items to as well
You can use align-self
to shift individual child items to the left, center, or right too.
<div class="vertical"> <div>Stretch</div> <div class="self-start">Start</div> <div class="self-center">Center</div> <div class="self-end">End</div></div>
Basic Usage
vertical
lets you lay things out vertically. It’s display: flex
+ flex-flow: column
with a couple of enhancements.
<div class="vertical"> <div>One</div> <div>Two</div> <div>Three</div></div>
Changing Gap
You can change the gap
between items with the gap
property or the --gap
variable.
<div class="vertical gap-8"> <div>One</div> <div>Two</div> <div>Three</div></div>
<div class="vertical" style="--gap:2rem"> <div>One</div> <div>Two</div> <div>Three</div></div>
Horizontal Alignment
vertical
uses align-items
to align items horizontally.
<div class="vertical items-stretch">...</div><div class="vertical items-start">...</div><div class="vertical items-center">...</div><div class="vertical items-end">...</div>
<div class="vertical" style="align-items: stretch">...</div><div class="vertical" style="align-items: start">...</div><div class="vertical" style="align-items: center">...</div><div class="vertical" style="align-items: end">...</div>
Aligning children items
You can use align-self
to align each child item individually.
<div class="vertical"> <div>Default</div> <div class="self-start">Start</div> <div class="self-center">Center</div> <div class="self-end">End</div></div>
Expanding Items with flex-grow
vertical
uses flexbox under the hood, so you can use flex-grow
to expand a child item vertically if the height of the container allows it to expand.
This technique is used in shell-simple
to expand content
to fill up the remaining height of the container so footer
stays at the bottom.
<div class="grid-auto-fr"> <div class="vertical"> <div class="flex-grow">Top</div> <div>Bottom</div> </div> <div>...</div></div>
<div class="grid-auto-fr"> <div class="vertical"> <div style="flex-grow: 1">Top</div> <div>Bottom</div> </div> <div>...</div></div>
There are two items in this sidebar. The first item has flex-grow
set to 1
so it will expand to fill the remaining height of the container. The second item has no flex-grow
so it will stay at the bottom.
The rest of this content is filler text so you can see the effect. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Officiis cumque aliquid magnam culpa et dolore eveniet laboriosam voluptas ea.
Spacer Items
vertical
also has spacer
items that lets you create space between items. As with the previous section on expanding items, this will only work if your vertical
layout contains sufficient height.
spacer
just sets margin-block-start: auto
.
<div class="grid-auto-fr"> <div class="vertical"> <div>Top</div> <div class="spacer">Bottom</div> </div> <div>...</div></div>
<div class="grid-auto-fr"> <div class="vertical"> <div>Top</div> <div class="mt-auto">Bottom</div> </div> <div>...</div></div>
There are two items in this sidebar. The bottom item has margin-top
set to auto
so it sticks to the bottom of the sidebar.
The rest of this content is filler text so you can see the effect. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Officiis cumque aliquid magnam culpa et dolore eveniet laboriosam voluptas ea.
Vertical to Horizontal
One of the most common responsive tactics is to switch from a vertical
layout to a horizontal
layout when there is enough space. You can use Tailwind Responsive modifiers to do this.
<div class="vertical md:vertical"> <div>One</div> <div>Two</div> <div>Three</div></div>
Basic Usage
vertical
lets you lay things out vertically. It’s display: flex
+ flex-flow: column
with a couple of enhancements.
<div class="vertical"> <div>One</div> <div>Two</div> <div>Three</div></div>
Changing Gap
You can change the gap
between items with the gap
property or the --gap
variable.
<div class="vertical gap-8"> <div>One</div> <div>Two</div> <div>Three</div></div>
<div class="vertical" style="--gap:2rem"> <div>One</div> <div>Two</div> <div>Three</div></div>
Horizontal Alignment
vertical
uses align-items
to align items horizontally.
<div class="vertical items-stretch">...</div><div class="vertical items-start">...</div><div class="vertical items-center">...</div><div class="vertical items-end">...</div>
<div class="vertical" style="align-items: stretch">...</div><div class="vertical" style="align-items: start">...</div><div class="vertical" style="align-items: center">...</div><div class="vertical" style="align-items: end">...</div>
Aligning children items
You can use align-self
to align each child item individually.
<div class="vertical"> <div>Default</div> <div class="self-start">Start</div> <div class="self-center">Center</div> <div class="self-end">End</div></div>
Expanding Items with flex-grow
vertical
uses flexbox under the hood, so you can use flex-grow
to expand a child item vertically if the height of the container allows it to expand.
This technique is used in shell-simple
to expand content
to fill up the remaining height of the container so footer
stays at the bottom.
<div class="grid-auto-fr"> <div class="vertical"> <div class="flex-grow">Top</div> <div>Bottom</div> </div> <div>...</div></div>
<div class="grid-auto-fr"> <div class="vertical"> <div style="flex-grow: 1">Top</div> <div>Bottom</div> </div> <div>...</div></div>
There are two items in this sidebar. The first item has flex-grow
set to 1
so it will expand to fill the remaining height of the container. The second item has no flex-grow
so it will stay at the bottom.
The rest of this content is filler text so you can see the effect. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Officiis cumque aliquid magnam culpa et dolore eveniet laboriosam voluptas ea.
Spacer Items
vertical
also has spacer
items that lets you create space between items. As with the previous section on expanding items, this will only work if your vertical
layout contains sufficient height.
spacer
just sets margin-block-start: auto
.
<div class="grid-auto-fr"> <div class="vertical"> <div>Top</div> <div class="spacer">Bottom</div> </div> <div>...</div></div>
<div class="grid-auto-fr"> <div class="vertical"> <div>Top</div> <div class="mt-auto">Bottom</div> </div> <div>...</div></div>
There are two items in this sidebar. The bottom item has margin-top
set to auto
so it sticks to the bottom of the sidebar.
The rest of this content is filler text so you can see the effect. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Officiis cumque aliquid magnam culpa et dolore eveniet laboriosam voluptas ea.
Vertical to Horizontal
One of the most common responsive tactics is to switch from a vertical
layout to a horizontal
layout when there is enough space. You can use Tailwind Responsive modifiers to do this.
<div class="vertical md:vertical"> <div>One</div> <div>Two</div> <div>Three</div></div>
Please purchase a license to view this content
This content is part of our premium documentation. To access it, you'll need to have an active license for one of these products.
If you already have a license, please login to access this content.
Here’s the CSS for vertical
.
.vertical { display: flex; flex-direction: column; gap: var(--gap-y, var(--gap)) var(--gap-x, var(--gap));
> .spacer { margin-block-start: auto; }
> *, > :where(.contents) > *, > *:where(astro-island, astro-slot) > * { flex-grow: var(--grow); }}
Here’s the CSS for vertical
.
.vertical { display: flex; flex-direction: column; gap: var(--gap-y, var(--gap)) var(--gap-x, var(--gap));
> .spacer { margin-block-start: auto; }
> *, > :where(.contents) > *, > *:where(astro-island, astro-slot) > * { flex-grow: var(--grow); }}
Please purchase a license to view this content
This content is part of our premium documentation. To access it, you'll need to have an active license for one of these products.
If you already have a license, please login to access this content.
Vertical
Horizontal alignment classes
Class | Description |
---|---|
items-stretch | Default value. Stretch items. |
items-start | Aligns items to the left. |
items-center | Aligns items to the center. |
items-end | Aligns items to the right. |
CSS Variables
Variable | Default | Description |
---|---|---|
--gap-x | 1rlh | Gap between on the x-axis |
--gap-y | 1rlh | Gap between rows on the y-axis |
--gap | 1rlh | Gap between items on both axes. --gap-x and --gap-y will override this value. |
Children
Horizontal alignment classes
Class | Description |
---|---|
self-start | Aligns item to the left. |
self-center | Aligns item to the center. |
self-end | Aligns item to the right. |
self-stretch | Default value. Stretches the item. |
Vertical Alignment
Class | Description |
---|---|
spacer | Creates a gap between this item and the one before |
flex-grow | Expands child to fill up available space |
CSS Variables
Variable | Default | Description |
---|---|---|
--grow | - | Whether to use flex-grow on the item |
Vertical
Horizontal alignment classes
Class | Description |
---|---|
items-stretch | Default value. Stretch items. |
items-start | Aligns items to the left. |
items-center | Aligns items to the center. |
items-end | Aligns items to the right. |
CSS Variables
Variable | Default | Description |
---|---|---|
--gap-x | 1rlh | Gap between on the x-axis |
--gap-y | 1rlh | Gap between rows on the y-axis |
--gap | 1rlh | Gap between items on both axes. --gap-x and --gap-y will override this value. |
Children
Horizontal alignment classes
Class | Description |
---|---|
self-start | Aligns item to the left. |
self-center | Aligns item to the center. |
self-end | Aligns item to the right. |
self-stretch | Default value. Stretches the item. |
Vertical Alignment
Class | Description |
---|---|
spacer | Creates a gap between this item and the one before |
flex-grow | Expands child to fill up available space |
CSS Variables
Variable | Default | Description |
---|---|---|
--grow | - | Whether to use flex-grow on the item |
Please purchase a license to view this content
This content is part of our premium documentation. To access it, you'll need to have an active license for one of these products.
If you already have a license, please login to access this content.