热门面试题与答案和在线测试
面向面试准备、在线测试、教程与实战练习的学习平台

通过聚焦学习路径、模拟测试和面试实战内容持续提升技能。

WithoutBook 将分主题面试题、在线练习测试、教程和对比指南整合到一个响应式学习空间中。

Chapter 2

CSS Syntax, Selectors, Declarations, Comments, and File Organization

Learn the basic structure of CSS rules and how selectors and declarations work in maintainable stylesheets.

Inside this chapter

  1. Basic CSS Rule Structure
  2. Common Selectors
  3. External, Internal, and Inline CSS
  4. Comments and Readability
  5. Organizing Stylesheets
  6. Practical Example

Series navigation

Study the chapters in order for the clearest path from CSS basics and styling foundations to advanced layout, responsive design, architecture, and maintainable interface systems. Use the navigation at the bottom to move smoothly through the full tutorial series.

Tutorial Home

Chapter 2

Basic CSS Rule Structure

h1 {
  color: #1f3a5f;
  font-size: 32px;
}

A CSS rule has a selector and a declaration block. The selector chooses which elements are targeted. The declaration block contains property-value pairs that define how those elements should appear.

Chapter 2

Common Selectors

  • Element selectors such as p or h1
  • Class selectors such as .card
  • ID selectors such as #mainHeader
  • Attribute selectors such as input[type="email"]
  • Combinators such as descendant or child selectors
Chapter 2

External, Internal, and Inline CSS

Professional projects usually prefer external stylesheets because they are reusable and easier to maintain. Internal CSS is useful for quick demos or isolated pages. Inline styles should be limited because they mix presentation directly into markup and can make code harder to manage.

Chapter 2

Comments and Readability

/* Primary hero heading styles */
.hero-title {
  font-size: 48px;
}

Comments should explain intent or structure when helpful, not restate obvious property lines. Good naming and grouping are just as important as comments.

Chapter 2

Organizing Stylesheets

Students should build the habit of grouping related rules, keeping selectors readable, and organizing CSS in a way that mirrors page structure or component structure rather than letting styles become an unstructured long file.

Chapter 2

Practical Example

A landing page stylesheet may group rules into header, hero, features, testimonials, pricing, and footer sections. That kind of organization helps teams change designs without hunting through scattered declarations.

版权所有 © 2026,WithoutBook。