如何为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
相关产品推荐
相关产品推荐

