Labs projects are experimental packages available for early feedback. Responsive Layout - Viewport
By optionally importing the responsive viewport layout module, you extend the nve-layout system using CSS Media Queries for adaptive responsive design based on the browser viewport width rather than the container element's width.
Learn more about media queries in this Mozilla
MDN documentation.
The responsive layout API applies conditional styling based on browser viewport width. Supported features include gap, padding, row vs column, reversing flex direction, and varying grid structure across defined pixel width breakpoints.
The following set of viewport breakpoint-values defines:
sm = 576px md = 768px lg = 1024px xl = 1280px xxl = 1440px
The at-symbol-based @breakpoint-size|... API adds the breakpoint size before the layout modifier.
Conditional gap sizing example: nve-layout="row @sm|gap:xs @md|gap:md @lg|gap:xxl". The size value after the : corresponds to one of the nine spacing/padding system values.
<section nve-layout="row @sm|gap:xxs @md|gap:md @lg|gap:xl @xl|gap:xl">
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card nve-display="@sm|hide"></nve-card>
</section>
<section nve-layout="row @sm|gap:xxs @md|gap:md @lg|gap:xl @xl|gap:xl">
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card nve-display="@sm|hide"></nve-card>
</section>
Viewport-based responsive layout responds to the browser window size, not the container size. Use
Container Queries if you need container-aware responsive behavior.
Responsive Gap Sizing
The following media query breakpoints are available for gap, replace ... with one of the 9 gap spacing values:
@sm|gap:... @md|gap:... @lg|gap:... @xl|gap:... @xxl|gap:...
<section nve-layout="row align:center @sm|gap:xs @md|gap:lg @lg|gap:xl @xl|gap:xxl">
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card></nve-card>
</section>
<section nve-layout="row align:center @sm|gap:xs @md|gap:lg @lg|gap:xl @xl|gap:xxl">
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card></nve-card>
</section>
Responsive Padding
The following media query breakpoints are available for padding, replace ... with one of the 9 padding values:
@sm|pad:... @md|pad:... @lg|pad:... @xl|pad:... @xxl|pad:...
<section nve-layout="row @sm|pad:xs @md|pad:lg @lg|pad:lg @xl|pad:xxl">
<nve-card nve-layout="full"></nve-card>
</section>
<section nve-layout="row @sm|pad:xs @md|pad:lg @lg|pad:lg @xl|pad:xxl">
<nve-card nve-layout="full"></nve-card>
</section>
Breakpoints for Switching Flexbox Layout Direction
The following media query breakpoints are available for swapping flex direction:
Horizontally
@sm|row @md|row @lg|row @xl|row @xxl|row
Vertically
@sm|column @md|column @lg|column @xl|column @xxl|column
<section nve-layout="column gap:sm @sm|row @sm|gap:xxl">
<nve-logo size="lg" color="purple-violet">1</nve-logo>
<nve-logo size="lg" color="purple-violet">2</nve-logo>
<nve-logo size="lg" color="purple-violet">3</nve-logo>
<nve-logo size="lg" color="purple-violet">4</nve-logo>
<nve-logo size="lg" color="purple-violet">5</nve-logo>
</section>
<section nve-layout="column gap:sm @sm|row @sm|gap:xxl">
<nve-logo size="lg" color="purple-violet">1</nve-logo>
<nve-logo size="lg" color="purple-violet">2</nve-logo>
<nve-logo size="lg" color="purple-violet">3</nve-logo>
<nve-logo size="lg" color="purple-violet">4</nve-logo>
<nve-logo size="lg" color="purple-violet">5</nve-logo>
</section>
Reverse Direction
Also, you can use the following syntax for flipping the flex direction:
@...|row-reverse @...|column-reverse
<style>
nve-logo.large {
--width: 200px;
--height: 200px;
}
</style>
<section nve-layout="column gap:lg @sm|row-reverse">
<nve-logo class="large" color="purple-violet">A</nve-logo>
<nve-logo class="large" color="purple-violet">B</nve-logo>
</section>
<style>
nve-logo.large {
--width: 200px;
--height: 200px;
}
</style>
<section nve-layout="column gap:lg @sm|row-reverse">
<nve-logo class="large" color="purple-violet">A</nve-logo>
<nve-logo class="large" color="purple-violet">B</nve-logo>
</section>
Responsive Grid
You can vary grid structure based on viewport size using the following syntax with nve-layout=grid...:
<section nve-layout="grid gap:md span-items:12 @sm|span-items:6 @md|span-items:4 @lg|span-items:3">
<nve-logo size="lg" color="purple-plum">1</nve-logo>
<nve-logo size="lg" color="purple-plum">2</nve-logo>
<nve-logo size="lg" color="purple-plum">3</nve-logo>
<nve-logo size="lg" color="purple-plum">4</nve-logo>
<nve-logo size="lg" color="purple-plum">5</nve-logo>
<nve-logo size="lg" color="purple-plum">6</nve-logo>
<nve-logo size="lg" color="purple-plum">7</nve-logo>
<nve-logo size="lg" color="purple-plum">8</nve-logo>
</section>
<section nve-layout="grid gap:md span-items:12 @sm|span-items:6 @md|span-items:4 @lg|span-items:3">
<nve-logo size="lg" color="purple-plum">1</nve-logo>
<nve-logo size="lg" color="purple-plum">2</nve-logo>
<nve-logo size="lg" color="purple-plum">3</nve-logo>
<nve-logo size="lg" color="purple-plum">4</nve-logo>
<nve-logo size="lg" color="purple-plum">5</nve-logo>
<nve-logo size="lg" color="purple-plum">6</nve-logo>
<nve-logo size="lg" color="purple-plum">7</nve-logo>
<nve-logo size="lg" color="purple-plum">8</nve-logo>
</section>
Or:
<section nve-layout="grid gap:md">
<nve-card nve-layout="span-items:12 @sm|span:4 @md|span:6 @lg|span:8"></nve-card>
<nve-card nve-layout="span-items:12 @sm|span:8 @md|span:6 @lg|span:4"></nve-card>
<nve-card nve-layout="span-items:12 @sm|span:8 @md|span:6 @lg|span:4"></nve-card>
<nve-card nve-layout="span-items:12 @sm|span:4 @md|span:6 @lg|span:8"></nve-card>
</section>
<section nve-layout="grid gap:md">
<nve-card nve-layout="span-items:12 @sm|span:4 @md|span:6 @lg|span:8"></nve-card>
<nve-card nve-layout="span-items:12 @sm|span:8 @md|span:6 @lg|span:4"></nve-card>
<nve-card nve-layout="span-items:12 @sm|span:8 @md|span:6 @lg|span:4"></nve-card>
<nve-card nve-layout="span-items:12 @sm|span:4 @md|span:6 @lg|span:8"></nve-card>
</section>
Responsive Grid Parent
<section nve-layout="grid gap:md span-items:12 @sm|span-items:6 @md|span-items:4 @lg|span-items:3">
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card></nve-card>
</section>
<section nve-layout="grid gap:md span-items:12 @sm|span-items:6 @md|span-items:4 @lg|span-items:3">
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card></nve-card>
<nve-card></nve-card>
</section>
Responsive Grid Items
<section nve-layout="grid gap:md">
<span nve-layout="@sm|span:4 @md|span:6 @lg|span:8"><nve-card></nve-card></span>
<span nve-layout="@sm|span:8 @md|span:6 @lg|span:4"><nve-card></nve-card></span>
<span nve-layout="@sm|span:8 @md|span:6 @lg|span:4"><nve-card></nve-card></span>
<span nve-layout="@sm|span:4 @md|span:6 @lg|span:8"><nve-card></nve-card></span>
</section>
<section nve-layout="grid gap:md">
<span nve-layout="@sm|span:4 @md|span:6 @lg|span:8"><nve-card></nve-card></span>
<span nve-layout="@sm|span:8 @md|span:6 @lg|span:4"><nve-card></nve-card></span>
<span nve-layout="@sm|span:8 @md|span:6 @lg|span:4"><nve-card></nve-card></span>
<span nve-layout="@sm|span:4 @md|span:6 @lg|span:8"><nve-card></nve-card></span>
</section>
Hiding Elements Based on Viewport Size
Since hiding elements only affects the display of the element itself and not the layout of its children, responsive visibility control uses the nve-display attribute.
Element visibility (hiding) uses the separate nve-display attribute rather than nve-layout. This distinction exists because visibility control only affects the element itself, while layout properties affect how the parent arranges children.
The following attributes are available for hiding elements at specific viewport breakpoints and below:
nve-display="hide" nve-display="@sm|hide" nve-display="@md|hide" nve-display="@lg|hide" nve-display="@xl|hide" nve-display="@xxl|hide"
You may want to now show elements at smaller viewport widths. The following attributes are available for showing elements at specific viewport breakpoints and below:
nve-display="@sm|show" nve-display="@md|show" nve-display="@lg|show" nve-display="@xl|show" nve-display="@xxl|show"
<section nve-layout="row gap:lg">
<nve-logo size="lg" color="purple-violet">1</nve-logo>
<nve-logo size="lg" color="purple-violet">2</nve-logo>
<nve-logo size="lg" color="purple-violet">3</nve-logo>
<nve-logo size="lg" color="purple-violet">4</nve-logo>
<nve-logo size="lg" color="purple-violet" nve-display="@sm|hide">5</nve-logo>
<nve-logo size="lg" color="purple-violet" nve-display="@sm|hide">6</nve-logo>
<nve-logo size="lg" color="purple-violet" nve-display="@sm|hide">7</nve-logo>
<nve-logo size="lg" color="purple-violet" nve-display="@md|hide">8</nve-logo>
<nve-logo size="lg" color="purple-violet" nve-display="@md|hide">9</nve-logo>
<nve-logo size="lg" color="purple-violet" nve-display="@md|hide">10</nve-logo>
<nve-logo size="lg" color="purple-violet" nve-display="@lg|hide">11</nve-logo>
<nve-logo size="lg" color="purple-violet" nve-display="@lg|hide">12</nve-logo>
<nve-logo size="lg" color="purple-violet" nve-display="@sm|show">13</nve-logo>
</section>
<section nve-layout="row gap:lg">
<nve-logo size="lg" color="purple-violet">1</nve-logo>
<nve-logo size="lg" color="purple-violet">2</nve-logo>
<nve-logo size="lg" color="purple-violet">3</nve-logo>
<nve-logo size="lg" color="purple-violet">4</nve-logo>
<nve-logo size="lg" color="purple-violet" nve-display="@sm|hide">5</nve-logo>
<nve-logo size="lg" color="purple-violet" nve-display="@sm|hide">6</nve-logo>
<nve-logo size="lg" color="purple-violet" nve-display="@sm|hide">7</nve-logo>
<nve-logo size="lg" color="purple-violet" nve-display="@md|hide">8</nve-logo>
<nve-logo size="lg" color="purple-violet" nve-display="@md|hide">9</nve-logo>
<nve-logo size="lg" color="purple-violet" nve-display="@md|hide">10</nve-logo>
<nve-logo size="lg" color="purple-violet" nve-display="@lg|hide">11</nve-logo>
<nve-logo size="lg" color="purple-violet" nve-display="@lg|hide">12</nve-logo>
<nve-logo size="lg" color="purple-violet" nve-display="@sm|show">13</nve-logo>
</section>
Summary
The viewport query responsive system allows elements to adapt based on the browser window width using the @ prefix. Remember:
- Layout properties (
gap, padding, row/column, grid) use nve-layout - Visibility control (
hide/show) uses nve-display - Viewport queries respond to the entire browser window
- Breakpoints range from
sm (576px) to xxl (1440px)
Example combining both:
<section nve-layout="row @md|gap:lg">
<div>Always visible</div>
<div nve-display="@md|hide">Hidden when viewport ≥ 768px</div>
</section>
<section nve-layout="row @md|gap:lg">
<div>Always visible</div>
<div nve-display="@md|hide">Hidden when viewport ≥ 768px</div>
</section>