You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为UnoCSS的Tailwind 4预设添加自定义主题间距?

解决@unocss/preset-wind4自定义间距不生效的问题

@unocss/preset-wind4 的主题配置逻辑和 v3 不一样了,不能再把自定义的 spacing、colors 放在根级的 theme 字段里,得把这些配置直接传给 presetWind() 的参数:

import { defineConfig } from "unocss";
import presetWind from "@unocss/preset-wind4";

export default defineConfig({
  presets: [
    presetWind({
      theme: {
        colors: {
          veryCool: "#0ff",
        },
        spacing: {
          md: "24rem",
        },
      },
    }),
  ],
});

修改后,你的测试代码 <div class="text-very-cool p-md">12312</div> 就能正确应用24rem的padding,同时自定义颜色也能正常生效。

内容的提问来源于stack exchange,提问作者Arseniy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 11:40:55