Tailwind / Nuxt UI Classic Patterns Quick Reference
A quick reference table of high-frequency, directly reusable style patterns accumulated during the development of this project. Covers positioning, frosted glass floating islands, Tailwind 4 new syntax, Nuxt UI theme color aliases, animation coordination, etc.
1. Positioning / Centering Trio
Absolute centering for elements of any width (most classic)
<div class="fixed left-1/2 -translate-x-1/2">
...
</div>left-1/2: Places the top-left corner of the element at the horizontal center of the screen-translate-x-1/2: Pulls it back by half of its own width to achieve true geometric centering- Does not depend on specific px values; works for any width, more elegant than
margin-left: -w/2
Top floating island (commonly used for navigation / FAB)
<div class="fixed top-2 sm:top-4 left-1/2 -translate-x-1/2 z-10">
...
</div>Refer to app/components/AppHeader.vue in this project.
2. Frosted Glass Floating Island (macOS style)
Breakdown:
| Class | Meaning |
|---|---|
bg-muted/80 | Nuxt UI theme color muted at 80% opacity, used as the blurred base |
backdrop-blur-sm | Blurs the content behind, the core "frosted glass" texture |
rounded-full | Capsule shape (semicircles at both ends) |
border border-muted/50 | Same color but lighter border for fine layering |
shadow-lg shadow-neutral-950/5 | Tailwind 4 split syntax, size + color independent, a light shadow (5% opacity) that is not jarring in bright scenarios |
Applicable to: any floating layer, popover, floating button, top navigation capsule.
3. Tailwind 4 New Syntax (High-Frequency Three Tricks)
1️⃣ Arbitrary CSS variable value
Equivalent to max-width: var(--ui-container). You can put any CSS variable inside the parentheses, replacing the old max-w-[1400px] fixed value.
2️⃣ data-attr state selector
Combined with Reka UI / Nuxt UI's automatic data-state toggle, pure CSS responds to component state without writing JS to switch classes.
3️⃣ important suffix
Tailwind 4 moves ! to the end (old version was !pt-0). Essential for overriding third-party library default styles — for example, overriding Nuxt UI component's built-in padding/ring.
4. Responsive Bleed + Container Width Lock
The classic combination to "bleed a block to full width but still be constrained by the UI container":
| Class | Meaning |
|---|---|
-mx-4 sm:-mx-12 lg:-mx-16 | Negative margins make the block eat back into the parent's padding, bleeding to the content edge |
max-w-(--ui-container) | But still locked by the Nuxt UI container width, preventing overflow |
Refer to the UCarousel viewport configuration in app/components/landing/Testimonials.vue of this project.
5. before: / after: Pseudo-element Decorations
Show on parent hover + slide (trio)
- Parent has
group - Child is permanently hidden (
opacity-0) group-hover:*: Child responds only when parent is hovered- Paired with
transition-allfor smooth transition
Refer to the "Read Article" arrow button in app/components/landing/Blog.vue of this project.
Applicable to: icons, badges, arrows, decorative elements that fade in on hover.
Large quotation mark decoration
Key point: content-[open-quote] is Tailwind 4 arbitrary value syntax, compiled to content: open-quote. Quotation marks are automatically rendered according to the document's lang (English " / Chinese 「」).
Refer to the UPageCTA in app/components/landing/Testimonials.vue of this project.
6. Nuxt UI Theme Color Aliases (Semantic Colors)
These classes cannot be found on the Tailwind official website, but they are everywhere in the project. View Nuxt UI Theme Documentation.
Color Aliases
| Alias | Meaning |
|---|---|
bg-default | Default page background |
bg-muted | Secondary surface color (card light background) |
bg-elevated | Raised surface (card / floating layer / selected state), slightly brighter than muted |
bg-accented | Further accent addition |
bg-highlighted | Highlighted selection |
bg-inverted | Inverted background |
text-default | Main text color |
text-muted | Secondary text |
text-dimmed | Very secondary text (decorative elements, icon strokes often use this) |
text-hi | Emphasized text |
text-inverted | Inverted text |
High-Frequency Combinations
Semi-transparent card background
60% transparent raised color, giving the card a "slightly lifted" feel.
Subtle hover feedback
Changes to the secondary color at 50% opacity on mouse enter, providing subtle hover feedback without being too flashy.
Active state text color switching (Nuxt UI standard!)
When Reka UI state toggles, it automatically toggles data-state, and pure CSS responds passively.
Refer to the UTabs style override in app/components/landing/FAQ.vue of this project.
7. group + group-hover: Coordination Mechanism
Parent has group, child uses group-hover:* to respond to parent hover — the core pattern of Tailwind for not writing JS to switch classes.
Key points:
- The child is permanently hidden (
opacity-0), so the mouse cannot hover over it directly - Mouse hovers over any part of the parent → child responds
- Combined with
group-data-[state=open]:*, it can also respond to the parent's specific data-state
80% of hover coordination in web animations relies on this, common to both React and Vue projects.
8. Animation Performance Suite
For animation scenarios like collapse, drawer, tab switching, add these two to elements undergoing transform to prevent frame drops:
| Class | Meaning |
|---|---|
transform-gpu | Forces the element to use GPU compositing layer rendering |
will-change-transform | CSS hint, tells the browser in advance "this element's transform is about to change", enabling early optimization |
Refer to the UAccordion trigger style in app/components/landing/FAQ.vue of this project.
9. Other Common Quick Notes
| Scenario | Class String |
|---|---|
| Long text ellipsis | truncate (= overflow:hidden; text-overflow:ellipsis; white-space:nowrap) |
| Short text line width balance | text-balance (browser automatically balances line length, preventing the end of a testimonial from having only 1-2 characters) |
| Prevent accidental line break | text-nowrap |
| Compact card hover feedback | hover:bg-muted/50 + rounded-lg + px-3 py-2 |
Complete Cheatsheet
| Scenario | Key Class String |
|---|---|
| Top centered floating island | fixed top-X left-1/2 -translate-x-1/2 z-10 |
| Frosted glass capsule | bg-muted/80 backdrop-blur-sm rounded-full border border-muted/50 shadow-lg shadow-neutral-950/5 |
| Show on parent hover + slide | opacity-0 group-hover:opacity-100 group-hover:translate-x-1 transition-all (parent has group) |
| Override third-party default styles | pt-0! / px-0! (Tailwind 4 important suffix) |
| Reka UI state text color switching | data-[state=active]:text-highlighted data-[state=inactive]:text-muted |
| Child responds to parent data-state | group-data-[state=open]:rotate-135 (parent has group) |
| Bleed to full width + lock UI container width | -mx-4 sm:-mx-12 lg:-mx-16 max-w-(--ui-container) |
| Decorative CSS large quotation marks | before:content-[open-quote] before:text-7xl before:absolute before:-ml-10 |
| GPU boost for smooth animation | transform-gpu will-change-transform |
| Simple large text + balanced line width | text-balance |
| Prevent line break | text-nowrap |
| Long text ellipsis | truncate |
| Semi-transparent card background | bg-elevated/60 |
| Subtle hover feedback | hover:bg-muted/50 |
Frequently Asked Questions
Q: Why can't I find bg-elevated / text-muted etc. on the Tailwind official website?
A: These are semantic color aliases injected by Nuxt UI itself (Semantic Colors), based on CSS variables, automatically following light/dark mode switching. Check the Semantic Colors section in the Nuxt UI Theme Documentation, not the Tailwind native classes.
Q: What is the ! suffix?
A: Tailwind 4's important syntax, placed at the end of the class (e.g., pt-0!), equivalent to padding-top: 0 !important, mainly used to override third-party library default styles.
Q: Do group and group-hover: have to be used together?
A: Yes. group is marked on the parent, and group-hover:* only takes effect when the parent is hovered. Writing group-hover:* alone without group on the parent will not be recognized by Tailwind and will not work.
New classic patterns encountered in the future will be added to this document.
Comments
No comments yet. Say something?