Cursor rule
.cursor/rules/tailwind-css-color-mix.mdcTailwind CSS 结合十六进制 CSS 变量与透明度时的避坑指南及 color-mix 原生替代方案
Cursor rules
Quality
50/100
Scores the file, not the repository.Length
141 words
6 headings · 3 code blocksRepository
34
— · pushed 25 days agoLast changed
3 days ago
First indexed 3 days ago.1234567# Tailwind CSS 变量透明度与原生 CSS 避坑指南89当项目中的 CSS 变量(如 `--muted-foreground`)定义为**绝对十六进制值**(如 `#a0a0a0`)时,在与 Tailwind 的透明度修饰符(如 `/30`)结合使用,或在全局原生伪元素(如 `::-webkit-scrollbar`)中混用时,极易产生编译失败或浏览器无法识别的无效 CSS。1011## 核心避坑规则1213### 1. 谨慎在伪元素/原生 CSS 中使用 `@apply` 加透明度1415当全局变量为 `#hex` 格式时,Tailwind 会将 `@apply bg-muted-foreground/30` 尝试编译为 `rgba(#a0a0a0, 0.3)`,这是**非法的 CSS 语法**,会导致浏览器静默丢弃该规则(例如导致自定义滚动条样式失效,回退为原生丑陋的样式)。1617```css18/* ❌ BAD: 当变量是十六进制时,会编译出非法 CSS rgba(#a0a0a0, 0.3) */19::-webkit-scrollbar-thumb {20 @apply bg-muted-foreground/30 rounded-full;21}22```2324### 2. 使用 `color-mix()` 作为安全、现代的透明度替代方案2526在必须写原生 CSS(如自定义滚动条)或者脱离 Tailwind 工具类的地方,**请直接使用现代原生的 `color-mix` 函数**来进行颜色和透明度的混合。它能完美解析十六进制变量并实现等效的透明度效果!2728```css29/* ✅ GOOD: 使用纯原生现代 CSS 函数进行透明度混合,100% 兼容十六进制变量 */30::-webkit-scrollbar-thumb {31 background-color: color-mix(in srgb, var(--muted-foreground) 30%, transparent);32 border-radius: 9999px;33}34```3536### 3. 注意原生属性对颜色的支持格式3738在如 `scrollbar-color` 等原生属性中,同样不可使用 `hsl(var(--xxx) / 0.3)` 去包裹一个十六进制变量。3940```css41/* ❌ BAD: 将十六进制传入 hsl 函数也是非法的 */42* {43 scrollbar-color: hsl(var(--muted-foreground) / 0.3) transparent;44}4546/* ✅ GOOD: 统一使用 color-mix 解决透明度混合 */47* {48 scrollbar-color: color-mix(in srgb, var(--muted-foreground) 30%, transparent) transparent;49}50```5152## 适用场景53当你修改全局 `style.css`、自定义浏览器原生控件样式(如滚动条、range input 等)或在 `.vue` 组件的 `<style>` 块中编写原生 CSS 且需要结合透明度时,请务必遵守此规则,首选 `color-mix()`。
Also in NoDeskAI/browser-pilot
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| NoDeskAI/browser-pilot.cursor/rules/build-from-user-perspective.mdc · 34 | Cursor rules | buildsecurity | 51/100 | 3 days ago | |
| NoDeskAI/browser-pilot.cursor/rules/debug-container.mdc · 34 | Cursor rules | api | 65/100 | 3 days ago | |
| NoDeskAI/browser-pilot.cursor/rules/deploy.mdc · 34 | Cursor rules | no sections | 38/100 | 3 days ago | |
| NoDeskAI/browser-pilot.cursor/rules/env-vars.mdc · 34 | Cursor rules | setup | 63/100 | 3 days ago | |
| NoDeskAI/browser-pilot.cursor/rules/fingerprint-popover-sync.mdc · 34 | Cursor rules | no sections | 25/100 | 3 days ago | |
| NoDeskAI/browser-pilot.cursor/rules/keyboard-shortcuts-ux.mdc · 34 | Cursor rules | ui | 31/100 | 3 days ago | |
| NoDeskAI/browser-pilot.cursor/rules/plan-ui-summary.mdc · 34 | Cursor rules | ui | 54/100 | 3 days ago | |
| NoDeskAI/browser-pilot.cursor/rules/ux-ui-daynight.mdc · 34 | Cursor rules | lint-formatui | 54/100 | 3 days ago | |
| NoDeskAI/browser-pilot.cursor/rules/verify-before-claim.mdc · 34 | Cursor rules | no sections | 50/100 | 3 days ago |
Diff against .cursor/rules/build-from-user-perspective.mdc Diff against .cursor/rules/debug-container.mdc Diff against .cursor/rules/deploy.mdc Diff against .cursor/rules/env-vars.mdc Diff against .cursor/rules/fingerprint-popover-sync.mdc Diff against .cursor/rules/keyboard-shortcuts-ux.mdc Diff against .cursor/rules/plan-ui-summary.mdc Diff against .cursor/rules/ux-ui-daynight.mdc Diff against .cursor/rules/verify-before-claim.mdc
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 3 days ago | |
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 3 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 3 days ago |
