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

Working with sections

2m:43s

On a page, we tend to have sections. Sometimes these sections have different background colors. For these, you want the padding between the sections to be uniform so there is consistency and a feeling of order.

Content
Content

There’s an easy way to set this up with a few classes:

  1. section
  2. section-mini
  3. section-cont

The Section Utility

In a section utility, I tend to add a padding-block to create the uniform spaces between sections, as I mentioned before. This is very intuitive and shouldn’t be a problem for you.

.section {
padding-block: var(--spacing-section);
}

Then creating the sections with different background colors is a simple matter of adding the background color to the section in the HTML.

<section class="section bg-blue-300">…</section>
<section class="section bg-purple-300">…</section>

Just like with wrappers, I realized that the padding can and should change at different breakpoints to make them look more right — based on the size of the viewport available.

Doing this is simple because we can just change the --spacing-section CSS variable.

:root {
--spacing-section: 3rlh;
@media (width >= 800px) {
--spacing-section: 4rlh;
}
}
Resize to see this work!
Content
Content

Mini Sections

Some sections — like a strip of logos — don’t contain much content and shouldn’t occupy the same amount of whitespace.

These sections should have smaller paddings. I create this through a utility called section-mini.

<section class="section bg-blue-300">Normal</section>
<section class="section-mini bg-purple-300">Mini</section>
Content
Content

And I start with a default of giving it half the whitespace given to the section utility. To make CSS variables work with Tailwind theme values, we can include an inline property to the theme declaration.

@theme inline {
--spacing-section: 2.5rlh;
--spacing-section-mini: calc(var(--spacing-section) * 0.5);
}
.section-mini {
padding-block: var(--spacing-section-mini);
}

Continuous sections

Sometimes you want two sections of the same color, but they should not have double the amount of padding between them.

For situations like this, I created the section-cont (short for continuous) utility.

<section class="section bg-blue-300">Normal</section>
<section class="section-cont bg-blue-300">Continuous</section>

In this case, the padding between these two sections should equal one full section-padding value. So I set padding-top of the 2nd section block to 0.

.section-cont {
padding-block: var(--spacing-section-cont);
.section + &,
& + & {
padding-block-start: 0;
}
}

Here’s an example of this at work. (Dotted borders for illustration purposes).

Lorem ipsum dolor sit amet consectetur, adipisicing elit. Sed asperiores suscipit minus doloribus adipisci, mollitia similique maxime impedit perspiciatis debitis obcaecati nisi nobis assumenda quidem! Quos ipsa fuga voluptate distinctio!

Lorem ipsum dolor sit amet consectetur, adipisicing elit. Sed asperiores suscipit minus doloribus adipisci, mollitia similique maxime impedit perspiciatis debitis obcaecati nisi nobis assumenda quidem! Quos ipsa fuga voluptate distinctio!