Start with a usable base style, then enhance it with modern features when available. Test actual target browsers, keep fallbacks simple, and avoid unnecessary duplication.
Practice Exercise
Create a reusable card component using custom properties, native nesting, logical padding and margins, a fluid width, and an @supports enhancement. Test a right-to-left text direction.
Quiz — 10 MCQs
- What does var() retrieve? (A) A custom property value (B) An HTML tag (C) A database field automatically (D) A JavaScript function result. Answer: A. Var references CSS custom properties.
- What does the ampersand mean in native CSS nesting? (A) The parent selector in nested selector patterns (B) A database join (C) A color format (D) A URL. Answer: A. The nesting selector represents the parent selector.
- What does padding-inline control? (A) Padding on inline-start and inline-end (B) Only the physical top side (C) Font size (D) Background color. Answer: A. It controls the two sides of the inline axis.
- What does padding-block control? (A) Block-start and block-end padding (B) Only physical left padding (C) Font family (D) Grid tracks. Answer: A. It sets padding along the block axis.
- Why use logical properties? (A) To adapt to writing modes and direction (B) To remove accessibility (C) To disable the cascade (D) To prevent all margins. Answer: A. They align styles with logical axes rather than fixed physical sides.
- What does writing-mode affect? (A) Text flow orientation and block/inline axes (B) Server settings (C) Database encoding only (D) Font downloads only. Answer: A. Writing mode defines the orientation of lines and axes.
- What does @supports do? (A) Tests CSS feature support (B) Defines HTML structure (C) Creates a database (D) Replaces media queries in all cases. Answer: A. It conditionally applies styles based on feature support.
- What is a fallback in var(--color, blue)? (A) blue, if the custom property cannot provide a usable value (B) Always the first value (C) A selector (D) A media query. Answer: A. The second argument is the fallback value.
- What is progressive enhancement? (A) Start with a usable base and add supported enhancements (B) Require the newest browser for all content (C) Remove all fallback styles (D) Use only inline CSS. Answer: A. Core functionality remains usable while supported features enhance it.
- What does text-wrap: balance aim to improve? (A) The balance of line lengths, especially in headings (B) Database normalization (C) Border radius (D) Image aspect ratio. Answer: A. It can improve visual line balance in supported browsers.
Key Takeaways
- Use custom properties for reusable design values.
- Native nesting groups related rules.
- Logical properties improve internationalized layouts.
- Use feature queries and progressive enhancement for modern CSS.