编程语言/tailwindcss:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第2行: 第2行:


[https://tailwindcss.com/docs/detecting-classes-in-source-files#class-detection-in-depth 检测源文件中的类]
[https://tailwindcss.com/docs/detecting-classes-in-source-files#class-detection-in-depth 检测源文件中的类]
== 主题 ==
[https://tailwindcss.com/docs/theme theme] 默认情况下在当前文件的文本域中,一定要在顶层引用 tailwindcss 之后主题才会生效,在文档中此处被称之为“<code>最终 CSS 输出中将仅生成使用的 CSS 变量</code>”,那么什么是<code>将仅生成使用</code>呢,很有歧义


{{hc|head=assets/module/theme.css|output=<syntaxhighlight lang="bash">
/* 生效 */
@import 'tailwindcss';
@theme {
  --ci-dark-bg: #121212;
}
</syntaxhighlight>}}
{{Leftrightflex|{{hc|head=assets/module/theme.css|output=<syntaxhighlight lang="bash">
/* 不生效 */
@theme {
  --ci-dark-bg: #121212;
}
</syntaxhighlight>}}|{{hc|head=assets/index.css|output=<syntaxhighlight lang="bash">
/* 生效 */
@import 'tailwindcss';
@import './module/theme.css';
</syntaxhighlight>}}}}


== preflight ==
== preflight ==

2025年7月31日 (四) 17:17的版本

标题文本

检测源文件中的类

主题

theme 默认情况下在当前文件的文本域中,一定要在顶层引用 tailwindcss 之后主题才会生效,在文档中此处被称之为“最终 CSS 输出中将仅生成使用的 CSS 变量”,那么什么是将仅生成使用呢,很有歧义

assets/module/theme.css
/* 生效 */
@import 'tailwindcss';
@theme {
  --ci-dark-bg: #121212;
}

模板:Leftrightflex

preflight

在构建过程中去掉 layer(base) 以便添加自定义的基础样式。tailwindcss 的 preflight 基础样式是基于 modern-normalize,而我常用的是 normalize.css,两者之间仍有差别。

@layer theme, base, components, utilities;
@import 'tailwindcss/theme.css' layer(theme);
@import 'tailwindcss/utilities.css' layer(utilities);

暗黑模式

暗黑模式如果只是页面中元素的样式改变,直接参阅 tailwindcss 文档就可以。但如果关联了第三方应用(eq: codemirror)就需要借助一些持久化函数

@custom-variant dark (&:where(.dark, .dark *));
/* @custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *)); */