编程语言/tailwindcss:修订间差异
来自康健生活
小 文字替换 -“{{Leftrightflex|”替换为“{{Double-columns|” 标签:ReplaceText 移动版编辑 移动版网页编辑 |
|||
| (未显示同一用户的3个中间版本) | |||
| 第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>}} | |||
如果单独使用 <code>theme.css</code> 文件是一定不会生效的,但是不管几层文件引用,只要最上层存在 <code>@import 'tailwindcss';</code> 便会生效。 | |||
{{Double-columns|{{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>}}}} | |||
但是如果在 js 文件中引用分开便不会生效 | |||
{{Double-columns|{{hc|head=assets/module/theme.css|output=<syntaxhighlight lang="bash"> | |||
/* 不生效 */ | |||
@theme { | |||
--ci-dark-bg: #121212; | |||
} | |||
</syntaxhighlight>}}|{{hc|head=src/main.ts|output=<syntaxhighlight lang="bash"> | |||
/* 不生效 */ | |||
import './assets/tailwind.css' | |||
import './assets/index.css' | |||
</syntaxhighlight>}}}} | |||
也就说我们可以理解一个 css 文件在 js 中的引用,便形成一个独立的上下文,在相同上下文中 css 的多层引用嵌套不会影响主题的生成,但是如果拆分开分别通过 js 的 impoert 引用就会形成上下文隔离,主题就会因为内部计算 <code>将仅生成使用</code> 时判断零使用而生成空主题。 | |||
这个时候可以通过 [https://tailwindcss.com/docs/theme#generating-all-css-variables static] 标识突破这种隔离,但是不利于 tree shaking。 | |||
<syntaxhighlight lang="css"> | |||
@theme static {}</syntaxhighlight> | |||
== preflight == | == preflight == | ||
| 第14行: | 第56行: | ||
== 暗黑模式 == | == 暗黑模式 == | ||
[https://tailwindcss.com/docs/dark-mode 暗黑模式]如果只是页面中元素的样式改变,直接参阅 tailwindcss 文档就可以。但如果关联了第三方应用(eq: codemirror)就需要借助一些持久化函数 | [https://tailwindcss.com/docs/dark-mode 暗黑模式]如果只是页面中元素的样式改变,直接参阅 tailwindcss 文档就可以。但如果关联了第三方应用(eq: codemirror)就需要借助一些持久化函数 | ||
<syntaxhighlight lang="css"> | |||
@custom-variant dark (&:where(.dark, .dark *)); | |||
/* @custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *)); */ | |||
</syntaxhighlight> | |||