Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Tailwind CSS advanced layout techniques from the Claude Plugin Marketplace collection.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: tailwindcss-advanced-layouts3description: |4Tailwind CSS advanced layout techniques including CSS Grid and Flexbox patterns.5PROACTIVELY activate for: (1) building complex layouts with CSS Grid, (2) grid-template-areas via Tailwind v4 arbitrary values, (3) responsive grid (grid-cols-*, auto-fit, minmax), (4) Flexbox patterns (flex-1, flex-grow, gap), (5) sticky headers and footers, (6) holy grail layout, (7) masonry-style layouts, (8) container queries (@container) with Tailwind, (9) subgrid usage, (10) aspect-ratio utilities, (11) magazine-style multi-column layouts.6Provides: Grid template recipes, container-query patterns, holy-grail templates, masonry alternatives, and aspect-ratio examples.7---89# Tailwind CSS Advanced Layout Techniques1011## CSS Grid Mastery1213### Complex Grid Layouts1415```html16<!-- Holy Grail Layout -->17<div class="grid min-h-screen grid-rows-[auto_1fr_auto]">18<header class="bg-white shadow">Header</header>19<div class="grid grid-cols-[250px_1fr_300px]">20<aside class="bg-gray-50 p-4">Sidebar</aside>21<main class="p-6">Main Content</main>22<aside class="bg-gray-50 p-4">Right Sidebar</aside>23</div>24<footer class="bg-gray-800 text-white">Footer</footer>25</div>2627<!-- Responsive Holy Grail -->28<div class="grid min-h-screen grid-rows-[auto_1fr_auto]">29<header>Header</header>30<div class="grid grid-cols-1 md:grid-cols-[250px_1fr] lg:grid-cols-[250px_1fr_300px]">31<aside class="order-2 md:order-1">Sidebar</aside>32<main class="order-1 md:order-2">Main</main>33<aside class="order-3 hidden lg:block">Right</aside>34</div>35<footer>Footer</footer>36</div>37```3839### Grid Template Areas4041```css42@utility grid-areas-dashboard {43grid-template-areas:44"header header header"45"nav main aside"46"nav footer footer";47}4849@utility area-header { grid-area: header; }50@utility area-nav { grid-area: nav; }51@utility area-main { grid-area: main; }52@utility area-aside { grid-area: aside; }53@utility area-footer { grid-area: footer; }54```5556```html57<div class="grid grid-areas-dashboard grid-cols-[200px_1fr_250px] grid-rows-[60px_1fr_40px] min-h-screen">58<header class="area-header bg-white shadow">Header</header>59<nav class="area-nav bg-gray-100">Navigation</nav>60<main class="area-main p-6">Main Content</main>61<aside class="area-aside bg-gray-50 p-4">Sidebar</aside>62<footer class="area-footer bg-gray-800 text-white">Footer</footer>63</div>64```6566### Auto-Fill and Auto-Fit Grids6768```html69<!-- Auto-fill: Creates as many tracks as fit, even empty ones -->70<div class="grid grid-cols-[repeat(auto-fill,minmax(250px,1fr))] gap-6">71<div class="bg-white rounded-lg shadow p-4">Card 1</div>72<div class="bg-white rounded-lg shadow p-4">Card 2</div>73<div class="bg-white rounded-lg shadow p-4">Card 3</div>74</div>7576<!-- Auto-fit: Collapses empty tracks -->77<div class="grid grid-cols-[repeat(auto-fit,minmax(250px,1fr))] gap-6">78<!-- Cards stretch to fill available space -->79</div>8081<!-- With arbitrary values -->82<div class="grid grid-cols-[repeat(auto-fill,minmax(min(100%,300px),1fr))] gap-4">83<!-- Handles edge case where container is smaller than minmax min -->84</div>85```8687### Subgrid8889```css90/* Enable subgrid in v4 */91@utility subgrid-cols {92grid-template-columns: subgrid;93}9495@utility subgrid-rows {96grid-template-rows: subgrid;97}98```99100```html101<div class="grid grid-cols-4 gap-4">102<!-- Span 2 columns but align children to parent grid -->103<div class="col-span-2 grid subgrid-cols gap-4">104<div>Aligned to parent column 1</div>105<div>Aligned to parent column 2</div>106</div>107</div>108```109110## Advanced Flexbox Patterns111112### Space Distribution113114```html115<!-- Equal spacing with first/last at edges -->116<div class="flex justify-between">117<div>First</div>118<div>Second</div>119<div>Third</div>120</div>121122<!-- Equal spacing everywhere including edges -->123<div class="flex justify-around">124<div>Item</div>125<div>Item</div>126<div>Item</div>127</div>128129<!-- Double space between items vs edges -->130<div class="flex justify-evenly">131<div>Item</div>132<div>Item</div>133<div>Item</div>134</div>135```136137### Flexible Item Sizing138139```html140<!-- Items share space equally -->141<div class="flex">142<div class="flex-1">1/3</div>143<div class="flex-1">1/3</div>144<div class="flex-1">1/3</div>145</div>146147<!-- First item takes 2x space -->148<div class="flex">149<div class="flex-[2]">2/4</div>150<div class="flex-1">1/4</div>151<div class="flex-1">1/4</div>152</div>153154<!-- Fixed + flexible -->155<div class="flex">156<div class="w-64 shrink-0">Fixed 256px</div>157<div class="flex-1 min-w-0">Flexible (can shrink)</div>158</div>159160<!-- Prevent shrinking with text overflow -->161<div class="flex min-w-0">162<div class="shrink-0">Icon</div>163<div class="min-w-0 truncate">Very long text that should truncate</div>164</div>165```166167### Masonry-Like with Flexbox168169```html170<!-- Column-based masonry -->171<div class="flex flex-col flex-wrap h-[800px] gap-4">172<div class="w-[calc(33.333%-1rem)] h-48">Item 1</div>173<div class="w-[calc(33.333%-1rem)] h-64">Item 2</div>174<div class="w-[calc(33.333%-1rem)] h-32">Item 3</div>175<!-- Items flow vertically then wrap to next column -->176</div>177```178179## Container Queries180181### Basic Container Queries182183```css184@plugin "@tailwindcss/container-queries";185```186187```html188<!-- Define container -->189<div class="@container">190<!-- Respond to container width -->191<div class="flex flex-col @md:flex-row @lg:grid @lg:grid-cols-3 gap-4">192<div>Item 1</div>193<div>Item 2</div>194<div>Item 3</div>195</div>196</div>197```198199### Named Containers200201```html202<!-- Multiple named containers -->203<div class="@container/sidebar">204<nav class="@[200px]/sidebar:flex-col @[300px]/sidebar:flex-row">205Navigation206</nav>207</div>208209<div class="@container/main">210<article class="@[600px]/main:prose-lg @[900px]/main:prose-xl">211Content212</article>213</div>214```215216### Container Query Units217218```html219<!-- Size relative to container -->220<div class="@container">221<h1 class="text-[5cqw]">Scales with container width</h1>222<p class="text-[3cqi]">Scales with container inline size</p>223</div>224```225226## Position and Layering227228### Sticky Positioning229230```html231<!-- Sticky header -->232<header class="sticky top-0 z-50 bg-white/80 backdrop-blur-sm border-b">233Navigation234</header>235236<!-- Sticky sidebar -->237<aside class="sticky top-20 h-[calc(100vh-5rem)] overflow-auto">238Sidebar content239</aside>240241<!-- Sticky table header -->242<div class="overflow-auto max-h-96">243<table>244<thead class="sticky top-0 bg-white shadow">245<tr>246<th class="sticky left-0 bg-white z-10">Corner cell</th>247<th>Column 2</th>248</tr>249</thead>250<tbody>...</tbody>251</table>252</div>253```254255### Fixed Elements256257```html258<!-- Fixed bottom navigation (mobile) -->259<nav class="fixed bottom-0 inset-x-0 z-50 bg-white border-t md:hidden">260<div class="flex justify-around py-2">261<a href="#">Home</a>262<a href="#">Search</a>263<a href="#">Profile</a>264</div>265</nav>266267<!-- Fixed action button -->268<button class="fixed bottom-6 right-6 z-40 rounded-full bg-brand-500 p-4 shadow-lg">269<PlusIcon />270</button>271```272273### Z-Index Management274275```css276@theme {277--z-dropdown: 100;278--z-sticky: 200;279--z-fixed: 300;280--z-modal-backdrop: 400;281--z-modal: 500;282--z-popover: 600;283--z-tooltip: 700;284--z-toast: 800;285}286287@utility z-dropdown { z-index: var(--z-dropdown); }288@utility z-sticky { z-index: var(--z-sticky); }289@utility z-fixed { z-index: var(--z-fixed); }290@utility z-modal-backdrop { z-index: var(--z-modal-backdrop); }291@utility z-modal { z-index: var(--z-modal); }292@utility z-popover { z-index: var(--z-popover); }293@utility z-tooltip { z-index: var(--z-tooltip); }294@utility z-toast { z-index: var(--z-toast); }295```296297## Overflow and Scrolling298299### Custom Scrollbars300301```css302@utility scrollbar-thin {303scrollbar-width: thin;304}305306@utility scrollbar-none {307scrollbar-width: none;308-ms-overflow-style: none;309}310311@utility scrollbar-none::-webkit-scrollbar {312display: none;313}314315/* Custom scrollbar styling */316@utility scrollbar-custom {317scrollbar-color: oklch(0.7 0 0) oklch(0.95 0 0);318}319320@utility scrollbar-custom::-webkit-scrollbar {321width: 8px;322height: 8px;323}324325@utility scrollbar-custom::-webkit-scrollbar-track {326background: oklch(0.95 0 0);327border-radius: 4px;328}329330@utility scrollbar-custom::-webkit-scrollbar-thumb {331background: oklch(0.7 0 0);332border-radius: 4px;333}334335@utility scrollbar-custom::-webkit-scrollbar-thumb:hover {336background: oklch(0.5 0 0);337}338```339340### Scroll Snap341342```html343<!-- Horizontal carousel -->344<div class="flex snap-x snap-mandatory overflow-x-auto gap-4 pb-4">345<div class="snap-start shrink-0 w-80">Card 1</div>346<div class="snap-start shrink-0 w-80">Card 2</div>347<div class="snap-start shrink-0 w-80">Card 3</div>348</div>349350<!-- Full-page sections -->351<div class="h-screen snap-y snap-mandatory overflow-y-auto">352<section class="h-screen snap-start">Section 1</section>353<section class="h-screen snap-start">Section 2</section>354<section class="h-screen snap-start">Section 3</section>355</div>356357<!-- Snap with padding -->358<div class="snap-x scroll-pl-6 overflow-x-auto">359<div class="snap-start">...</div>360</div>361```362363### Scroll Margin for Anchors364365```html366<!-- Offset for fixed header -->367<section id="about" class="scroll-mt-20">368<!-- Content appears below fixed header when linked -->369</section>370```371372## Aspect Ratio and Object Fit373374### Responsive Aspect Ratios375376```html377<!-- Fixed aspect ratio container -->378<div class="aspect-video bg-gray-100">379<video class="h-full w-full object-cover">...</video>380</div>381382<div class="aspect-square rounded-full overflow-hidden">383<img src="avatar.jpg" class="h-full w-full object-cover" />384</div>385386<!-- Custom aspect ratio -->387<div class="aspect-[4/3]">4:3 content</div>388<div class="aspect-[21/9]">Ultra-wide content</div>389```390391### Object Positioning392393```html394<!-- Focus on specific part of image -->395<div class="h-64 overflow-hidden">396<img397src="portrait.jpg"398class="h-full w-full object-cover object-top"399/>400</div>401402<!-- Arbitrary object position -->403<img class="object-cover object-[25%_75%]" src="..." />404```405406## Advanced Spacing407408### Logical Properties409410```html411<!-- Works for LTR and RTL -->412<div class="ps-4 pe-6 ms-auto">413Padding and margin that respect text direction414</div>415416<!-- Block direction (vertical in horizontal writing modes) -->417<div class="pbs-4 pbe-6 mbs-auto">418Block-direction spacing419</div>420```421422### Space Between with Dividers423424```html425<!-- Dividers between items -->426<ul class="divide-y divide-gray-200">427<li class="py-4">Item 1</li>428<li class="py-4">Item 2</li>429<li class="py-4">Item 3</li>430</ul>431432<!-- Horizontal dividers -->433<div class="flex divide-x divide-gray-200">434<div class="px-4">Section 1</div>435<div class="px-4">Section 2</div>436<div class="px-4">Section 3</div>437</div>438```439440### Negative Margins for Bleeds441442```html443<!-- Full-bleed image in padded container -->444<article class="px-6">445<p>Padded content</p>446<img src="hero.jpg" class="-mx-6 w-[calc(100%+3rem)]" />447<p>More padded content</p>448</article>449450<!-- Pull quote that breaks out -->451<div class="max-w-prose mx-auto px-4">452<p>Normal content...</p>453<blockquote class="-mx-8 md:-mx-16 px-8 md:px-16 py-8 bg-gray-100">454Featured quote that extends beyond content width455</blockquote>456</div>457```458459## Multi-Column Layout460461### Text Columns462463```html464<!-- Responsive columns -->465<div class="columns-1 sm:columns-2 lg:columns-3 gap-8">466<p>Content flows across columns...</p>467</div>468469<!-- Fixed-width columns -->470<div class="columns-[300px] gap-6">471<p>Creates as many 300px columns as fit</p>472</div>473474<!-- Prevent breaks inside elements -->475<div class="columns-2">476<div class="break-inside-avoid mb-4">477Card that stays together478</div>479</div>480```481482## Responsive Patterns483484### Container Queries + Media Queries485486```html487<div class="@container">488<div class="489/* Container query for component-level responsiveness */490@md:flex @md:gap-4491492/* Media query for page-level responsiveness */493lg:grid lg:grid-cols-2494">495Content496</div>497</div>498```499500### Breakpoint-Based Visibility501502```html503<!-- Show different content per breakpoint -->504<nav>505<!-- Mobile menu button -->506<button class="md:hidden">Menu</button>507508<!-- Desktop navigation -->509<ul class="hidden md:flex gap-4">510<li>Home</li>511<li>About</li>512<li>Contact</li>513</ul>514</nav>515```516517### Fluid Sizing with Clamp518519```html520<!-- Fluid padding -->521<section class="py-[clamp(2rem,5vw,6rem)] px-[clamp(1rem,3vw,4rem)]">522Content with responsive padding523</section>524525<!-- Fluid max-width -->526<div class="mx-auto w-full max-w-[clamp(300px,90vw,1200px)]">527Responsive container528</div>529```530531## Print Styles532533```html534<!-- Hide elements when printing -->535<nav class="print:hidden">Navigation</nav>536537<!-- Show only when printing -->538<div class="hidden print:block">Print-only content</div>539540<!-- Print-specific styles -->541<article class="print:text-black print:bg-white">542<h1 class="text-2xl print:text-xl">Heading</h1>543<a href="..." class="text-blue-500 print:text-black print:underline">544Link (shows as text when printed)545</a>546</article>547548<!-- Prevent page breaks -->549<div class="print:break-inside-avoid">550Keep this content together on one page551</div>552553<!-- Force page break -->554<div class="print:break-before-page">555Start on new page556</div>557```558559## Best Practices560561### 1. Use Modern Layout Methods562563```html564<!-- Prefer Grid for 2D layouts -->565<div class="grid grid-cols-3 gap-4">566567<!-- Prefer Flexbox for 1D layouts -->568<div class="flex items-center gap-2">569```570571### 2. Handle Edge Cases572573```html574<!-- Prevent flex item from overflowing -->575<div class="flex min-w-0">576<div class="min-w-0 truncate">Long text</div>577</div>578579<!-- Prevent grid blowout -->580<div class="grid grid-cols-1 min-w-0">581<div class="overflow-hidden">Content that might overflow</div>582</div>583```584585### 3. Use Semantic Sizing586587```html588<!-- Prefer max-w-prose for reading content -->589<article class="max-w-prose mx-auto">590591<!-- Use container for page sections -->592<div class="container mx-auto px-4">593```594595### 4. Test All Breakpoints596597Create systematic tests for all responsive layouts to ensure they work at every breakpoint.598