现在,只要用户的操作系统开启了深色模式,dark:{class}类将优先于无前缀的类。media策略在底层使用prefers-color-scheme媒体功能,但是,如果您想支持手动切换深色模式,您也可以使用 'class' 策略进行更多控制。 默认情况下,当darkMode启用时,只会为颜色相关的类生成dark变体,包括文本颜色、背景颜色、边框颜色、渐变色以及...
This Tailwind CSS plugin provides a flexible way to define and use color schemes in your Tailwind CSS project. It allows you to configure global colors, scheme-specific colors, and use these colors throughout your project with optional opacity. ...
border-color: var(--border-primary); } // 使用 CSS 包含查询优化选择器性能 @container (prefers-color-scheme: dark) { .dark-container { background-color: var(--bg-primary); color: var(--text-primary); } } // 使用 will-change 优化动画性能 .theme-transition { will-change: background-...
实现深色模式的切换功能: // 深色模式切换functionsetupThemeToggle(){constthemeToggleBtn=document.getElementById('theme-toggle');// 检查系统主题偏好if(window.matchMedia('(prefers-color-scheme: dark)').matches){document.documentElement.classList.add('dark');}// 检查本地存储的主题设置if(localStorage.t...
Tailwind 使用dark变量来定义深色样式(默认浅色),默认情况下,是使用 CSS 媒体查询prefers-color-scheme来识别系统模式并展示具体样式,示例代码:
新增实用工具类:包括inset-shadow-*、inset-ring-*、field-sizing-*、color-scheme-*、font-stretch-*等,满足不同场景需求。 变体增强:可组合变体,新增@starting-style、not-*、inert、nth-*、in-*等变体,open变体支持:popover-open伪类。 后代变体:新增**变体,用于选择所有后代元素,结合其他变体可精准筛选。
新增实用工具类:包括inset-shadow-*、inset-ring-*、field-sizing-*、color-scheme-*、font-stretch-*等,满足不同场景需求。 变体增强:可组合变体,新增@starting-style、not-*、inert、nth-*、in-*等变体,open变体支持:popover-open伪类。 后代变体:新增**变体,用于选择所有后代元素,结合其他变体可精准筛选。
新增实用工具类:包括inset-shadow-*、inset-ring-*、field-sizing-*、color-scheme-*、font-stretch-*等,满足不同场景需求。 变体增强:可组合变体,新增@starting-style、not-*、inert、nth-*、in-*等变体,open变体支持:popover-open伪类。 后代变体:新增**变体,用于选择所有后代元素,结合其他变体可精准筛选。
文档中还提供了一些钩子函数给我们使用,例如当我们想要支持暗黑模式时,我们可以使用setColorScheme来切换颜色模式。 代码语言:javascript 复制 import{colorScheme,useColorScheme}from"nativewind";// Use imperativelycolorScheme.set("dark"|"light"|"system");exportdefaultfunctionApp(){// Or as a hookconst{set...
// On page load or when changing themes, best to add inline in `head` to avoid FOUCif(localStorage.theme==='dark'|| (!('theme'inlocalStorage) &&window.matchMedia('(prefers-color-scheme: dark)').matches)) {document.documentElement.classList.add('dark') ...