Tailwind CSS 2.2 发布,快速构建 UI 的 CSS 框架

栏目: 软件资讯 · 发布时间: 2年前

内容简介:Tailwind CSS 2.2 正式发布,该版本是有史以来功能最丰富的 Tailwind 版本之一,该版本更新内容如下: 全新改进的Tailwind CLI 我们以性能优先的思维方式从头开始重写了 Tailwind CLI 工具,同时还增加了对一堆新...

Tailwind CSS 2.2 正式发布,该版本是有史以来功能最丰富的 Tailwind 版本之一,该版本更新内容如下:

全新改进的Tailwind CLI

我们以性能优先的思维方式从头开始重写了 Tailwind CLI 工具,同时还增加了对一堆新功能的支持:

npx tailwindcss -o dist/tailwind.css --watch --jit --purge="./src/**/*.html"

以下是一些亮点:

  • 无需安装或配置——只需 npx tailwindcss -o output.css 就能从任何地方编译 Tailwind。甚至可以使用该 -jit 标志启用 JIT 模式并使用该 -purge 选项传入内容文件,而无需创建配置文件;
  • Watch 模式 —— 这样就可以在进行任何更改时自动重建 CSS;
  • JIT 性能优化 —— 由于我们的 CLI 是特定于 Tailwind 的,我们能够进行大量优化,使其成为在 JIT 模式下编译 CSS 的最快构建工具;
  • 缩小支持 —— 现在可以使用 cssnano 通过添加 -minify 标志来缩小你的 CSS;
  • PostCSS 插件支持 —— 新的 CLI 将读取并尊重使用 postcss.config.js 文件配置的任何额外插件;

它与以前的 CLI 完全兼容,因此如果您已经设置了任何脚本,您应该能够升级到 v2.2,而无需对脚本进行任何更改。

伪元素变体前后

此功能仅在 Just-in-Time 模式下可用;

多年来很多用户一直想要这个功能,现在它终于来了!我们添加了对样式伪元素的第一方支持,例如beforeafter

<div class="before:block before:bg-blue-500 after:flex after:bg-pink-300"></div>

我们会在用户使用 before 或 after 变体时自动设置 content: "" 以确保呈现元素,但用户可以使用 content 具有完全任意值支持的新实用程序覆盖它:

<div class="before:content-['hello'] before:block ..."></div>

用户甚至可以使用 CSS attr() 函数从属性中获取内容:

<div before="hello world" class="before:content-[attr(before)] before:block ..."></div>

当内容中有空格时,这会非常有用,因为在 CSS 类名称中不能使用空格。

首字母/行变体

此功能仅在 Just-in-Time 模式下可用;

我们为first-letterfirst-line伪元素添加了变体,因此您可以执行首字下沉之类的操作:

<p class="first-letter:text-4xl first-letter:font-bold first-letter:float-left">
  The night was March 31, 1996, and it was finally time for Bret Hart to face off against Shawn
  Michaels in the long anticipated Iron Man match — a 60 minute war of endurance where the man who
  scored the most number of falls would walk away as the WWF World Heavyweight Champion.
</p>

We've added a new selection variant that makes it super easy to style highlighted to match your design:

选定的文本变体

此功能仅在 Just-in-Time 模式下可用;

我们添加了一个新的selection变体,使突出显示的样式变得非常容易以匹配设计:

<p class="selection:bg-pink-200">
  After nearly a grueling hour of warfare with neither man scoring a fall, Hart locked in the
  Sharpshooter, his signature submission hold. As Michaels screamed in pain, the crowd were certain
  that Hart was about to walk away from WrestleMania XII as the still-World Heavyweight Champion.
</p>

我们甚至以这样的方式构建了这个功能,它可以应用于父元素并向下级联,因此您可以通过将实用程序应用于正文来为整个站点设置高亮颜色:

<body class="selection:bg-pink-200">
  <!-- ... -->
  <p>
    But Michaels didn't give up — he held on until the bell rang and the designated 60 minutes was
    up. Hart walked away content, thinking that without a clear winner, the title was his to hold.
    He was not prepared for what would happen next, when Gorilla Monsoon declared the match would
    continue under sudden death rules.
  </p>
</body>

详尽的伪类支持

此功能仅在 Just in Time 模式下可用;

在这个版本中,我们基本上为每个我们能想到的缺失的伪类添加了变体:

  • only (only-child)
  • first-of-type
  • last-of-type
  • only-of-type
  • target
  • default
  • indeterminate
  • placeholder-shown
  • autofill
  • required
  • valid
  • invalid
  • in-range
  • out-of-range

列表中个人最喜欢的是 placeholder-shown ——当与新的 siblings 选择器变体结合时,它可以做一些很酷的事情,比如浮动标签:

<div class="relative">
  <input id="name" class="peer ...">
  <label for="name" class="peer-placeholder-shown:top-4 peer-focus:top-0 ...">
</div>

修复和改进

除了此版本引入的新功能外,我们还修复了一些可能困扰您的小问题。以下是自上次发布以来我们所做的修复和改进的列表:

  • JIT:支持应用重要的实用程序变体;
  • JIT:改进对 Svelte 类绑定的支持;
  • JIT:完善calcvar 在任意值的支持
  • 当转变不透明度时,转换hsl 颜色为hsla 而不是rgba
  • 修复backdropBlur未生成;
  • 改进 animation 值解析;
  • 散列配置时忽略未知对象类型;
  • 确保为具有 order-dependent 的实用程序的插件正确分组变体;
  • 解决相对于tailwind.config.js而不是当前工作目录的清除路径;
  • JIT:当节点临时目录保存在与项目本身不同的驱动器上时修复临时文件存储;
  • 支持 border-opacity 实用程序和默认border实用程序
  • JIT:修复扩展@tailwind指令的源映射
  • JIT:折叠相邻规则时忽略空格;
  • JIT:使用自定义分隔符时正确生成组父类;
  • JIT:修复多个group变体的错误堆叠;
  • JIT:修复由于保留未使用的上下文而导致的内存泄漏;

更多详情可查看:https://blog.tailwindcss.com/tailwindcss-2-2


以上所述就是小编给大家介绍的《Tailwind CSS 2.2 发布,快速构建 UI 的 CSS 框架》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Hacker's Delight

Hacker's Delight

Henry S. Warren Jr. / Addison-Wesley / 2002-7-27 / USD 59.99

A collection useful programming advice the author has collected over the years; small algorithms that make the programmer's task easier. * At long last, proven short-cuts to mastering difficult aspec......一起来看看 《Hacker's Delight》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换