Vertical Layout
Vertical layouts provide top-to-bottom content flow that aligns with reading patterns. The Elements vertical layout system uses CSS Flexbox to create stackable layouts that adapt to content and container constraints.
Learn flexbox concepts with the MDN Flexbox guide and practice with this visual Flexbox Froggy game.
Understanding Vertical Layout
Vertical flexbox layouts stack content with control over spacing, alignment, and distribution. They provide natural reading flow while supporting the layout requirements of modern interfaces.
When to Use Vertical Layout
Choose vertical layout (column) for:
- Forms: Labels above inputs, sections stacked vertically
- Card content: Header, body, and footer stacked naturally
- Sidebars: Navigation items or widgets stacked vertically
- Hero sections: Centered content with title, description, CTA
- Mobile layouts: Natural stacking for responsive design
- Article content: Paragraphs, images, and headings in sequence
- Modal dialogs: Header, content, and actions stacked
Note: vertical layouts are inherently mobile-friendly. Content that stacks vertically works naturally on narrow screens, and you can enhance it for larger displays.
Basic Setup
Set nve-layout="column" on a container element to create a vertical layout:
<!-- Simple vertical layout -->
<aside nve-layout="column">
<h2>Title</h2>
<p>Content goes here...</p>
<footer>Published today</footer>
</article>
!-- With gap spacing -->
<form nve-layout="column gap:md">
<nve-input label="Email">
<input type="text" placeholder="Email..."/>
</nve-input>
<nve-input label="Password" type="password">
<input type="text" placeholder="Password..."/>
</nve-input>
<nve-button>Sign In</nve-button>
</form>
<!-- With alignment -->
<section nve-layout="column align:center gap:xl">
<nve-logo size="lg"></nve-logo>
<h1 nve-text="display lg">Welcome</h1>
<p nve-text="heading sm">Get started with our platform</p>
</section>
Alignment Options
Vertical layouts support alignment along both axes:
Primary Axis (Vertical)
align:top- Items start from the top (default)align:vertical-center- Items centered verticallyalign:bottom- Items aligned to bottomalign:space-between- Items spread with space betweenalign:space-around- Items spread with space aroundalign:space-evenly- Items spread with even spacing
Cross Axis (Horizontal)
align:left- Items aligned to leftalign:horizontal-center- Items centered horizontallyalign:right- Items aligned to rightalign:horizontal-stretch- Items stretch to container width
Combined Alignment
align:center- Center both horizontally and verticallyalign:stretch- Stretch in both dimensions- You can combine many values:
align:horizontal-center align:bottom
Alignment mental model: in vertical layouts, the main axis runs top-to-bottom and the cross axis runs left-to-right. This reversal from horizontal layouts is key to understanding alignment behavior.
Vertical Layout Examples
<section nve-layout="column align:...">
Align Top
Align Vertical Center
Align Bottom
Align Horizontal Center
Align Center
Align Center and Bottom
Align Top and Right
Align Center and Right
Align Bottom and Right
Align Space Around
Align Space Between
Align Space Evenly
Align Stretch Horizontal
Align Stretch Vertical
Align Full Stretch
Flex Behavior in Vertical Layouts
Flex Growth
Control how items expand vertically:
<div nve-layout="column full">
<header>Fixed height header</header>
<main nve-layout="full">Expands to fill space</main>
<footer>Fixed height footer</footer>
</div>
Spacing Distribution
Use alignment to control vertical rhythm:
<!-- Equal spacing between items -->
<aside nve-layout="column align:space-between" style="height: 400px;">
<div>Top item</div>
<div>Middle item</div>
<div>Bottom item</div>
</aside>
<!-- Items grouped at top with space at bottom -->
<section nve-layout="column gap:md" style="height: 400px;">
<div>Item 1</div>
<div>Item 2</div>
<div nve-layout="full"></div> <!-- Spacer -->
<div>Footer item</div>
</section>
Best Practices
- Embrace natural flow: Vertical layouts match reading patterns
- Use consistent spacing: Apply gap values systematically
- Consider viewport height: Use
fullorvhunits for full-screen layouts - Plan for growth: Use
flex: 1to create expandable regions - Test with varied content: Ensure layouts work with different content lengths
Performance tip: when creating scrollable regions, constrain the height of the container rather than relying on max-height. This provides better performance and more predictable behavior.
Next Steps
- Explore horizontal layouts for side-by-side arrangements
- Learn about grid layouts for multi-dimensional designs
- Understand gap and padding spacing options