What Surprises Does Tailwind CSS v3.3 Bring?

发表于 2023-04-05 19:44 525 字 3 min read

cos avatar

cos

FE / ACG / 手工 / 深色模式强迫症 / INFP / 兴趣广泛养两只猫的老宅女 / remote

Tailwind CSS v3.3 推出了多项实用新特性,包括深色模式扩展调色板、渐变颜色精确控制、开箱即用的多行文本截断、字体大小与行高联合设置、CSS 变量简写语法、列表项目图片标记、断字控制及表格标题对齐等功能,极大提升了开发效率和灵活性。开发者可通过 npm 安装或 Tailwind Play 在线体验这些新功能。

This article has been machine-translated from Chinese. The translation may contain inaccuracies or awkward phrasing. If in doubt, please refer to the original Chinese version.

A colleague suddenly mentioned in our group chat: “This new feature in Tailwind v3.3 is pretty nice — you can finally write font size and line height in a single class.” So I took a break to check out the Tailwind update. Without further ado, here’s the summary:

Tailwind CSS v3.3 was released on March 28, 2023. It’s a fantastic release that brings many new features and improvements, making our development more efficient and flexible. In this article, I’ll introduce some of the most exciting new features, including:

  1. Extended color palette for darker darks: An extended color palette adding a deeper 950 shade for every color, now with 11 shades total, e.g., bg-slate-950

    image

  2. ESM and TypeScript support: Support for ESM and TypeScript configuration files, allowing you to configure Tailwind CSS with modern syntax and type checking.

  3. Fine-tune gradient color stop positions: Allows you to precisely control gradient effects by specifying the exact position of each color stop in the gradient, such as from-5%, via-35%, and to-85%

    image

  4. Line-clamp out of the box: Truncate multi-line text without a plugin, e.g., line-clamp-3.

    We released our official line-clamp plugin over two years ago, and even though it uses a bunch of weird deprecated -webkit-* stuff, it works in every browser and it’s going to work forever, so we decided to bake it right into the framework itself.

  5. New line-height shorthand for font-size utilities: This is very useful — you can set font size and line height with a single class (when not in the preset), e.g., text-lg/7, text-sm/[17px], text-[20px]/[24px]

    image

  6. CSS variables without the var(): Shorthand syntax for CSS variables, allowing you to use arbitrary values without the var() function: before: bg-[var(--brand-color)] after: bg-[--brand-color]

  7. Configurable font-variation-settings: Support for configuring font-variation-settings, letting you use font-* utilities to set font variations directly.

  8. New list-style-image utilities: This is also very useful — want to use images as your list item markers? Now you can with the new list-image-* utilities, e.g., list-image-[url(carrot.png)]

    image

  9. New hyphens utilities: For fine-tuning hyphenation behavior. Have you ever heard of the ­ HTML entity? Neither had we before adding support for these hyphens-* utilities. With hyphens-manual and carefully placed ­, you can tell the browser where to insert hyphens when it needs to break a word across multiple lines.

  10. New caption-side utilities: Utilities for controlling the alignment of caption elements within tables, allowing you to add captions to tables and set their position. See Caption Side for details.

    • caption-top positions the caption element at the top of the table
    • caption-bottom positions the caption element at the bottom of the table.

These are just some of the most notable new features. If you want to learn about more details and improvements, check out the full release notes. To upgrade to v3.3, simply install the latest tailwindcss package from npm:

npm install -D tailwindcss@latest

You can also try out all the new features online at Tailwind Play.

喜欢的话,留下你的评论吧~

© 2020 - 2026 cos @cosine
Powered by theme astro-koharu · Inspired by Shoka