Skip to content

Commit a2e0a23

Browse files
committed
feat: tailwind blog
1 parent ef9b46c commit a2e0a23

File tree

3 files changed

+105
-9
lines changed

3 files changed

+105
-9
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
Have you ever tried to center a title in a header, but also wanted a "Back" button or a breadcrumb on the far left?
2+
3+
If you just use `flex justify-between`, the title gets pushed off-center if the left and right items aren't exactly the same width. It looks messy.
4+
5+
Today, I'm going to show you the "Magic" behind perfectly centering an element while keeping a side item positioned absolutely, using **Tailwind CSS**.
6+
7+
## The Challenge
8+
9+
The goal is to have the **Title** perfectly centered in the container, regardless of how long the **Breadcrumb** text on the left is.
10+
11+
**The Solution: Absolute Positioning within a Relative Container.**
12+
13+
```jsx
14+
<div className="relative flex flex-col items-center justify-center mb-4">
15+
{/* Breadcrumb (Absolute on Desktop) */}
16+
<span className="md:absolute md:left-0 md:top-1/2 md:-translate-y-1/2 ...">
17+
fc::apps::tcg
18+
</span>
19+
20+
{/* Title (Flow Content) */}
21+
<h1 className="...">Techno TCG Maker</h1>
22+
</div>
23+
```
24+
25+
## Step-by-Step Breakdown
26+
27+
### 1. The Parent (`relative`)
28+
29+
```jsx
30+
<div className="relative flex flex-col items-center justify-center">
31+
```
32+
33+
* `relative`: This defines the "sandbox". Any child with `absolute` positioning will position itself relative to *this* box, not the whole page.
34+
* `flex flex-col items-center`: By default (mobile), this is just a vertical stack. The breadcrumb sits on top of the title.
35+
36+
### 2. The Breadcrumb (`absolute`)
37+
38+
```jsx
39+
<span className="md:absolute md:left-0 md:top-1/2 md:-translate-y-1/2">
40+
```
41+
42+
* `md:absolute`: On medium screens (desktop) and up, we rip this element out of the document flow. It no longer takes up space, so the Title (which is still in the flow) naturally snaps to the exact center of the parent.
43+
* `md:left-0`: "Go to the far left edge."
44+
* `md:top-1/2`: "Move your top edge to 50% of the container's height." (This alone actually makes it look too low).
45+
* `md:-translate-y-1/2`: "Slide yourself UP by 50% of your own height." **This is the golden rule** for vertically centering absolute items.
46+
47+
## Bonus: Coding Tailwind Like a Pro
48+
49+
To write "clean" Tailwind that produces complex layouts like this, follow these mental models:
50+
51+
### A. Think Mobile-First
52+
Notice how I wrote `flex-col` first, and then `md:absolute`?
53+
* **Bad:** Write for desktop, then try to fix it for mobile.
54+
* **Good:** Write for a narrow phone screen. Once that looks good, add `md:` prefix to change the layout for tablets/laptops.
55+
56+
### B. Master the "Invisible Box" (Flexbox)
57+
90% of layout is just Flexbox.
58+
* `flex justify-between`: Items push to edges (Left ... Right).
59+
* `flex justify-center`: Items bunch in the middle.
60+
* `gap-4`: The best way to space items. Never use `margin-right` on children if you can use `gap` on the parent.
61+
62+
### C. The "Text Gradient" Trick
63+
To get that shiny, futuristic text effect:
64+
1. `bg-gradient-to-r`: Define the gradient direction.
65+
2. `from-X to-Y`: Define the colors.
66+
3. `bg-clip-text text-transparent`: The specific magic that clips the colored background to the shape of the letters and makes the text fill invisible so the background shows through.
67+
68+
### D. Memorize the Spacing Scale
69+
Tailwind's scale is usually multiples of 4px (0.25rem).
70+
* `1` = 4px
71+
* `4` = 16px (Standard padding/margin)
72+
* `8` = 32px
73+
* `16` = 64px
74+
75+
Sticking to this rhythm makes your UI feel consistent and "professional" without you really trying.

public/posts/posts.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
[
2+
{
3+
"slug": "mastering-tailwind-centering",
4+
"title": "Mastering Tailwind CSS: The \"Absolute Centering\" Trick",
5+
"date": "2025-11-26",
6+
"updated": "2025-11-26",
7+
"description": "Learn how to perfectly center a title while keeping a side element positioned absolutely, ensuring a balanced layout regardless of content size.",
8+
"tags": [
9+
"tailwind",
10+
"css",
11+
"frontend",
12+
"layout",
13+
"tutorial"
14+
],
15+
"category": "dev",
16+
"filename": "mastering-tailwind-centering.txt",
17+
"authors": ["fezcode"],
18+
"image": "/images/defaults/sina-salehian-HqmTUJD73mM-unsplash.jpg"
19+
},
220
{
321
"slug": "gaussian-elimination",
422
"title": "Gaussian Elimination: The Swiss Army Knife of Linear Systems in Computer Engineering",

src/pages/apps/TcgCardGeneratorPage.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, {useState, useEffect, useRef} from 'react';
22
import {Link} from 'react-router-dom';
33
import {
4+
AcornIcon,
45
ArrowLeftIcon,
56
DownloadSimpleIcon,
67
UploadSimpleIcon,
@@ -370,17 +371,19 @@ const TcgCardGeneratorPage = () => {
370371
<div className="mx-auto max-w-7xl px-4 lg:px-8">
371372
{/* Header */}
372373
<div className="mb-10 text-center">
373-
<Link
374-
to="/apps"
375-
className="inline-flex items-center gap-2 text-sm font-medium text-gray-400 hover:text-primary-400 transition-colors mb-4"
376-
>
377-
<ArrowLeftIcon size={16}/> Back to Apps
374+
<Link to="/apps" className="text-article hover:underline flex items-center justify-center gap-2 text-lg mb-4">
375+
<ArrowLeftIcon size={24} /> Back to Apps
378376
</Link>
379-
<h1 className="text-4xl md:text-6xl font-black tracking-tighter flex items-center justify-center gap-3 mb-4">
380-
<span className="bg-clip-text text-transparent bg-gradient-to-r from-primary-400 to-secondary-400">
381-
Techno TCG Maker
377+
<div className="relative flex flex-col items-center justify-center mb-4">
378+
<span className="md:absolute md:left-0 md:top-1/2 md:-translate-y-1/2 text-xl md:text-2xl font-mono font-normal text-gray-500 tracking-tight mb-2 md:mb-0 opacity-75">
379+
fc<span className="text-gray-700">::</span>apps<span className="text-gray-700">::</span><span className="text-primary-400">tcg</span>
382380
</span>
383-
</h1>
381+
<h1 className="text-4xl md:text-6xl font-black tracking-tighter">
382+
<span className="bg-clip-text text-transparent bg-gradient-to-r from-primary-400 to-secondary-400">
383+
Techno TCG Maker
384+
</span>
385+
</h1>
386+
</div>
384387
<p className="text-gray-500 max-w-xl mx-auto">
385388
Design your own futuristic trading cards.
386389
</p>

0 commit comments

Comments
 (0)