现在仅需增加以下一行魔法 CSS:

html[theme='dark-mode'] {
    filter: invert(1) hue-rotate(180deg);
}

这个方法的唯一缺点是,它还会反转应用程序中的所有图像。

因此,我们将对所有图像添加相同的规则,以逆转效果。

html[theme='dark-mode'] img{
    filter: invert(1) hue-rotate(180deg);
}

我们还将向HTML元素添加一个 transition ,以确保过渡不会过于花哨!

html {
    transition: color 300ms, background-color 300ms;
}

【css】一行 CSS 为网页添加暗黑模式支持

相关文章:

  • 2021-06-13
  • 2021-05-03
  • 2022-12-23
  • 2022-12-23
  • 2021-04-06
  • 2022-02-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-27
  • 2021-12-07
  • 2022-12-23
  • 2021-06-12
  • 2021-08-19
相关资源
相似解决方案