Essential CSS
JavaScript Roadmap
Learn JavaScript
Mastering Web Typography
Practical Astro
Understanding Async JS
Unorthodox Tailwind
API Masterclass
Build and Deploy
The Beginner Freelancer
Real World Node
Profile Billing Logout
Unorthodox Tailwind
Lesson Plan
  1. Introduction
    1. Introduction
    2. What Tailwind brings to the table
    3. Tailwind: The Good and The Bad
    4. The First and Most Important Step
    5. Simple Unorthodox System
    6. The System I Use
  2. Tailwind Fundamentals
    1. Introduction
    2. Installing Tailwind
    3. Using Tailwind utilities
    4. Understanding Tailwind’s utility system
    5. Understanding Tailwind values
    6. Understanding Tailwind variants
  3. Unorthodox Fundamentals
    1. Introduction
    2. Making Simple Tailwind Utilities
    3. Components vs Utilities
    4. Specificity, Cascade, and CSS Layers
    5. Debugging Tailwind Styles
    6. Composable Utility System
    7. Create lots of components
  4. Layouts System
    1. Tailwind is great for layouts
    2. Four Types of Layouts
    3. Building Shell Layouts
    4. Building Macro Layouts
    5. Better Responsive Variants
    6. A collection of maximum widths
    7. A note on grid wrappers
    8. Working with sections
    9. Building Micro Layouts
    10. Positioning Layouts
  5. Typography System
    1. Introduction
    2. A system for using multiple typefaces
    3. Tailwind's font-size system
    4. Finding your font-size system
    5. My font-size system
    6. A simple responsive typography system
    7. The main body
    8. Vertical rhythm
  6. Theming System
    1. Introduction
    2. Tailwind's colour system
    3. The pigment system
    4. Tailwind's gradient system
    5. A friendlier gradient system
    6. Handling SVG fill and stroke
    7. Improving Tailwind's colour palette
    8. A simple way to theme
  7. Useful Tools
    1. Introduction
    2. Making functional utilities
    3. Custom variants
    4. Scaffolding tools
    5. Extending Tailwind
  8. Effects System
    1. Introduction
    2. Vertical text
    3. Strikethrough text
    4. Text stroke
    5. Highlighting text
    6. Nicer shadows
    7. Transitioning shadows
    8. Drop shadows
    9. Dark mode tricks
    10. Gradient borders
    11. More effects to explore
  9. Putting Everything Together
    1. The Unorthodox Tailwind process
    2. The 4 systems combined
    3. Create components liberally
    4. Advanced tips
    5. My CSS Structure
    6. A Cheatsheet
    7. Consolidating your thoughts
    8. Parting words

Positioning Layouts

7m:15s

Positioning Layouts are layouts that need to be positioned properly to shift things. The ones we’re talking about are position: relative, position: absolute, position: fixed, and position: sticky.

There are a variety of layouts that use these positions. We’re just going to go through a few of them here.

Absolute Positioning

Floating tags

Imagine for a moment that you have an element with a small floating tag at the top or at the top right like the one here.

To build this, you typically have to write position: absolute and adjust the top and right values to match the location you want.

.parent {
position: relative;
}
.floating-tag {
position: absolute;
top: -0.5em; /* tweak pixels! */
right: -8em; /* tweak pixels! */
}

This sort of thing is very easy with Splendid Layouts’ edge utilities. To achieve this one, there’s a utility called edge-topright-start, which basically means:

  • Top right edge
  • Start position (or left, based on logical properties).
<div class="relative">
<div class="edge-topright-start">Floating Tag</div>
<div>Your other content</div>
</div>
Floating Tag
Content goes here

But more often than not, you’ll find the tag at the top center of the component. Doing that is also very simple with Edge. We just have to specify edge-top

<div class="relative">
<div class="edge-top">Floating Tag</div>
<div>Your other content</div>
</div>
Floating Tag
Content goes here

Fixed Positioning

Toast

Toasts are small pop-up messages that can be placed almost anywhere near the edge of the viewport. They can be at the…

  • top
  • top left corner
  • top right corner
  • bottom left corner
  • bottom right corner
  • and bottom (though that’s rare)

Positioning the toast is quite simple. You just need to add position: fixed and let it float around with top, bottom, left, and right properties.

.toast {
position: fixed;
top: 1rem;
left: 1rem;
}

There’s nothing difficult about that. But what if you could write this positioning without any extra CSS?

This is where Splendid Layouts’ fixed- utilities come in handy. They use position: fixed to place elements at the edges of the viewport.

<div class="fixed-topleft">TopLeft</div>
<div class="fixed-top">Top</div>
<div class="fixed-topright">TopRight</div>
<div class="fixed-left">Left</div>
<div class="fixed-right">Right</div>
<div class="fixed-bottomright">BottomRight</div>
<div class="fixed-bottom">Bottom</div>
<div class="fixed-bottomleft">BottomLeft</div>
TopLeft
Top
TopRight
Left
Right

BottomRight

Bottom

BottomLeft

Then you can use nudge to adjust the position of the element towards the center of the viewport.

<div class="fixed-topleft nudge-4">TopLeft</div>
<div class="fixed-top nudge-4">Top</div>
<div class="fixed-topright nudge-4">TopRight</div>
<div class="fixed-left nudge-4">Left</div>
<div class="fixed-right nudge-4">Right</div>
<div class="fixed-bottomright nudge-4">BottomRight</div>
<div class="fixed-bottom nudge-4">Bottom</div>
<div class="fixed-bottomleft nudge-4">BottomLeft</div>

TopLeft

Top

TopRight

Left

Right

BottomRight

Bottom

BottomLeft

Drawers

I don’t think I need to explain what drawers are, but they are panels that open up and show you stuff. And they can be on the left or the right or the top or the bottom.

Drawer on this site!

The CSS for creating a drawer is simple as well. The key is to use fixed and top, left, and right to position the drawer.

/* left drawer */
.drawer {
position: fixed;
top: 0;
left: 0;
bottom: 0;
}

Here you can also use Splendid Layouts’ fixed utilities to create a drawer easily. In this case, we are just adding a keyword called full to the top, bottom, left, or right side.

Left Full
Right Full

Sticky Positioning

position: sticky is tricky — and it trips people up. To make sticky work, you have to satisfy three conditions:

  1. There must be a scrollable ancestor element. Usually, that would be the <body> element.
  2. The parent element of sticky must contain sufficient height for it to scroll.
  3. If scrolling vertically, the sticky element must have a top or bottom attribute to determine where it sticks. If scrolling horizontally, it must have a left or right attribute.

To create a sticky header, you just need to add position: sticky and a top property to the header. So there’s nothing difficult about this either.

.header {
position: sticky;
top: 0;
}

But what if you didn’t need to remember to write top or even a z-index value to keep it up at the top? That’s what Splendid Layouts’ sticky utility does in a nutshell.

<header class="sticky">Sticky Header</header>
Sticky Header

Absolute said to Relative, “I don’t need you.”

Relative smiled. “Then good luck — top: 10px from where, exactly?”

Fixed scrolled past, unbothered, glued to the glass, muttering something smug about viewports and permanence.

Sticky tried to commit but kept flinching at every threshold, half in, half out, never quite sure which parent to trust.

Static stood still and said nothing, as is tradition — the quiet default everyone forgets is already there.

Then z-index walked in and started a fight no one asked for, stacking contexts like grudges, refusing to explain the rules.

Transform passed through and accidentally trapped Fixed in a containing block, which nobody noticed until the bug report came in on Monday.

Float drifted by, ancient and tired, still owed an apology from 2003.

Flow watched it all from the side, quietly holding the layout together, not arguing, not escaping, not stacking, not sticking — the only one in the room who actually knew where anything belonged.

— Written by Shiz, my Claude Assistant

Sticky sidebars work when your content has sufficient height for it to scroll. So it’s important for the parent container to stretch the full length.

The simplest way to do this is use shell-simple. Then, you add a grid within the content. And set the sidebar to sticky.

<div class="shell-simple">
<div class="content">
<div class="grid-simple [--cols:3]">
<main class="[--span:2]">Content</main>
<aside class="sticky">Sticky Sidebar</aside>
</div>
</div>
</div>

Absolute said to Relative, “I don’t need you.”

Relative smiled. “Then good luck — top: 10px from where, exactly?”

Fixed scrolled past, unbothered, glued to the glass, muttering something smug about viewports and permanence.

Sticky tried to commit but kept flinching at every threshold, half in, half out, never quite sure which parent to trust.

Static stood still and said nothing, as is tradition — the quiet default everyone forgets is already there.

Then z-index walked in and started a fight no one asked for, stacking contexts like grudges, refusing to explain the rules.

Transform passed through and accidentally trapped Fixed in a containing block, which nobody noticed until the bug report came in on Monday.

Float drifted by, ancient and tired, still owed an apology from 2003.

Flow watched it all from the side, quietly holding the layout together, not arguing, not escaping, not stacking, not sticking — the only one in the room who actually knew where anything belonged.

— Written by Shiz, my Claude Assistant

Sticky Sidebar

Documentation and other utilities

We’ve covered almost every position utility Splendid Layouts provides.

  • edge
  • fixed
  • nudge
  • sticky

The only one I didn’t cover is pos. I rarely use it nowadays so I don’t find it important to talk about.

You can find out more about each of these utilities in the documentation.

That’s all you need to know about creating layouts with Tailwind!