而对于 css,我们为每一个与主题色相关的颜色添加一个与之对应的 dark-theme 样式。 那么,我们只需要即时切换 body 的 dark-theme 的出现与否,就能让浏览器为我们使用全新的样式和颜色。 编写 css 第一个要改变的,当然是背景色了。 如果原来的背景色是设置到 body 上的,那么我们就通过 .dark-theme 指定一个暗色版的背景色。 当然,如果希望立即能够看到效果,应该在 body 上加上 dark-theme 这个 class。 编写 js 其实我们的 js 只有一句话,就是切换 body 上的 dark-theme,所以我选择直接内联。
'dark-theme' : 'light-theme'" > This is how you add dynamic classes in Vue. </template> 如果darkMode为true,则将dark-theme用作我们的类名。 否则,我们选择light-theme。 当darkMode为 true 时,会把dark-theme作为一个动态类名应用于我们的元素。但是light-them不会被应用,因为!darkMode 值为false。 'dark-theme' : 'light-theme'" /> </template> 之所以起作用,是因为Vue直接在MovieList的根元素上设置类。 'dark-theme' : 'light-theme'; } } }; 这不仅易于阅读,而且还可以轻松添加新功能并在将来进行重构。
link的id是哪个,如果是默认主题的话,就传送新主题的id给change()函数,否则亦然 if (link.id === "default-theme") { change("dark-theme cookies了 document.cookie = "themeCookies=default-theme;path=/"; }else if(themeName === "dark-theme "){ link.id = "dark-theme"; link.href = '/static/bootstrap4.0.0/css/bootstrap_gray.min.css '; document.cookie = "themeCookies=dark-theme;path=/"; } } // 获取cookie中当前主题的id,没有则返回默认的default-theme
background-color: #f8f8f8; } .tab-button { background-color: #f8f8f8; } } theme.dark.scss: .dark-theme BehaviorSubject} from "rxjs/BehaviorSubject"; @Injectable() export class SettingDataProvider { // true: dark-theme settingDataProvider.getActiveTheme().subscribe(theme => { if (theme) { this.theme = 'dark-theme
hotpink; } /* in the middle */ article :is(header,footer) > p { color: gray; } /* at the end */ .dark-theme :where(button,a) { color: rebeccapurple; } /* multiple */ :is(.dark-theme, .dim-theme) :where(button p,blockquote) { color: black; } :is(.dark-theme.hero > h1) { font-weight: bold; } article:is(.dark-theme
background-color: var(--theme-color); } .button { background-color: var(--theme-color); } /* 切换主题 */ .dark-theme document.getElementById('toggleTheme').addEventListener('click', function() { document.body.classList.toggle('dark-theme
document.querySelector('.btn-toggle'); btn.addEventListener('click', function() { document.body.classList.toggle('dark-theme window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { document.body.classList.add('dark-theme '); } else { document.body.classList.remove('dark-theme'); } 用户偏好 这个功能其实是有真实的需求的,比如如果我们不记住用户偏好,那么肯定只能有一种默认值
dark-accent: mat-palette($mat-amber, A200, A100, A400); $dark-warn: mat-palette($mat-deep-orange); $dark-theme alternate dark theme instead of the default theme. .unicorn-dark-theme { @include angular-material-theme($dark-theme
页面布局与主题切换 项目采用响应式布局,通过一个外层容器(app-wrapper)控制整体背景色,并结合 dark-theme 类来实现主题切换。
$colors { #{$var-element}#{$name}: #{$color}; } } 参考文章: 深色模式适配指南 https://www.zoo.team/article/dark-theme
链接: https://developers.google.com/web/tools/chrome-devtools/customize/dark-theme 8.ColorZilla
颜色可以考虑2种主题,light-theme及dark-theme,俗称日间模式及夜间模式。 ? 2.4 字体 ? 一般包括从H1、H2、H3、H4、H5、p六种字体样式的设定。
/dark-theme'; // 创建一个 style 元素,用于插入 css 定义 const createStyle = (content) => { const style = document.createElement
fixBabelImports, addLessLoader } = require("customize-cra"); const darkThemeVars = require("antd/dist/dark-theme
color: @colors[text-color];}// 使用混合(mixin)实现主题定制body { .theme(light-theme);}.dark-mode { .theme(dark-theme
.light-theme { --card-bg: #eee; } .dark-theme { --card-bg: #111; } .card { background-color: var
editor-border', editor.editorBorder); // 添加主题类型 class document.body.classList.remove('light-theme', 'dark-theme
避免与 @scope的排序和范围之争: @scope (.light-theme) { a { color: purple; } } @scope (.dark-theme) { a { color