0Pricing
Tailwind CSS Academy · 课时

Tailwind 与传统 CSS

比较实用程序优先的样式编写方式与普通 CSS 和 BEM,了解每种方式适合发挥作用的场景。

Tailwind 与传统 CSS 是 CoddyKit 上的免费 Tailwind CSS Academy 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Tailwind CSS Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Tailwind CSS Academy 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

The Old Way: Semantic CSS

The old way is semantic CSS: descriptive class names like .navbar or .card in a separate file, meant to describe purpose. Methods like BEM grew from this.

/* Traditional CSS */
.hero-title {
  font-size: 3rem;
  font-weight: 800;
  color: #111827;
  letter-spacing: -0.025em;
  margin-bottom: 1.5rem;
}

<h1 class="hero-title">Build Something Great</h1>

What Is BEM?

BEM means Block, Element, Modifier: a Block like .card, an Element like .card__title, and a Modifier like .card--featured. Clear, but it takes discipline.

<!-- BEM naming convention -->
<div class="card card--featured">
  <img class="card__image" src="thumb.jpg" alt="" />
  <h2 class="card__title">Featured Post</h2>
  <p class="card__description">A short summary...</p>
  <a class="card__link card__link--primary" href="#">Read More</a>
</div>

The Same Card in Tailwind

Here is that same card in Tailwind. No CSS file at all — every choice shows in the HTML: rounded-xl shadow-md for shape, text-xl font-bold for the title.

<!-- Tailwind equivalent -->
<div class="rounded-xl shadow-md overflow-hidden bg-white border border-indigo-200">
  <img class="w-full h-48 object-cover" src="thumb.jpg" alt="" />
  <div class="p-6">
    <h2 class="text-xl font-bold text-gray-900 mb-2">Featured Post</h2>
    <p class="text-gray-500 text-sm mb-4">A short summary...</p>
    <a class="text-indigo-600 font-semibold hover:underline" href="#">Read More</a>
  </div>
</div>

The Specificity Problem in Traditional CSS

Traditional CSS has a specificity headache: rules fight over which wins, leading to !important everywhere and brittle code. Tailwind utilities stay predictable.

/* Specificity conflict example */
.sidebar .card .card__title { color: red; }    /* specificity: 0,3,0 */
.featured-section .card__title { color: blue; } /* specificity: 0,2,0 */

/* Which color wins? Depends on file order AND specificity */
/* This becomes unmanageable at scale */

CSS File Growth Over Time

Plain CSS files grow forever because nobody dares delete old rules. Tailwind strips unused utilities at build time, so your CSS never piles up dead weight.

Switching Between Files

With classic CSS you keep switching between HTML and CSS for every tweak. Tailwind keeps you in the HTML, which speeds up your workflow a lot.

<!-- With Tailwind: no CSS file to open -->
<button class="py-2 px-4 bg-green-500 text-white rounded hover:bg-green-600">
  Submit
</button>

<!-- With traditional CSS: go find/create .submit-button in your CSS file -->
<button class="submit-button">Submit</button>

When Traditional CSS Still Wins

Sometimes traditional CSS still wins: styling third-party HTML you cannot edit, complex keyframe animations, or a public stylesheet for other developers.

/* Complex animation: better in CSS than utility classes */
@keyframes wave {
  0%, 100% { transform: rotate(-10deg); }
  50% { transform: rotate(10deg); }
}
.wave-animation {
  animation: wave 1s ease-in-out infinite;
}

Consistency: Scales vs Freeform Values

Tailwind quietly enforces consistency. Instead of hand-typed 13px or 17px padding, you pick from a 4px scale, so designs stay harmonious by default.

<!-- Tailwind spacing: always consistent multiples -->
<div class="p-4">  <!-- 16px -->
<div class="p-6">  <!-- 24px -->
<div class="p-8">  <!-- 32px -->

<!-- vs Traditional CSS: any value is valid -->
div { padding: 13px; } /* Why 13? Nobody knows. */

Performance Comparison

Will all those classes hurt performance? No — repeated classes compress brilliantly, and Tailwind CSS is usually far smaller than an unoptimized stylesheet.

Team Onboarding: Tailwind vs CSS

Onboarding is easier too. Anyone who knows the Tailwind docs can read and edit any component, since class names mean the same thing in every project.

Choosing the Right Approach

So which to choose? Tailwind for app UI and design systems you control; traditional CSS for theming or CMS HTML. Many projects happily use both.

Quick Check

Quick check! Compare Tailwind and CSS in your head. ⚖️

Lesson Recap

Nice work! Traditional CSS names things in files while Tailwind composes in HTML, BEM does not fix file growth, and the scale enforces consistency. Next: typography.

常见问题解答

「Tailwind 与传统 CSS」课时是免费的吗?

是的 — 「Tailwind 与传统 CSS」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Tailwind CSS Academy 课程的其余内容,请升级到 CoddyKit PRO。 Tailwind CSS Academy 课程共包含 4 节课。

「Tailwind 与传统 CSS」这节课中我会学到什么?

比较实用程序优先的样式编写方式与普通 CSS 和 BEM,了解每种方式适合发挥作用的场景。 你通过在浏览器中直接运行的动手代码来练习 Tailwind CSS Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Tailwind CSS Academy 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Tailwind CSS Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。

「Tailwind 与传统 CSS」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Tailwind CSS Academy 课中编写并运行代码吗?

能。每节 Tailwind CSS Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 实用程序优先 CSS 详解
  2. 安装与配置 Tailwind
  3. 您的第一个 Tailwind 页面
  4. Tailwind 与传统 CSS
← 返回 Tailwind CSS Academy