GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — CSS 在夜间模式/深色模式中的使用与探索 · Issue #73 · chokcoco/iCSS

CSS 在夜间模式/深色模式中的使用与探索 #73

New issue
Copy link
New issue
Copy link
Open
Open
CSS 在夜间模式/深色模式中的使用与探索#73
Copy link
Labels
未完成

Description

@chokcoco
chokcoco
opened on Nov 29, 2019
Issue body actions

本文未完成....


法一:使用 filter: invert

主要借助 invert 这个滤镜实现,定义一个 .dark-mode-invert 挂载在全局根元素 <html>上:

filter: invert(): 反转输入图像。值定义转换的比例。100%的价值是完全反转。值为0%则图像无变化。值在0%和100%之间,则是效果的线性乘子。 若值未设置,值默认是0。

图片不能使用 filter: invert 处理,需要再 invert(100%) 转变回来。

.dark-mode-invert {
    filter: invert(100%);
}

.dark-mode-invert img {
    filter: invert(100%);
}

尝试使用掘金作为例子试了下:

转换前:
image

转换后:
image

缺点:

  1. 需要对图片额外处理,如果图片是以 background 嵌入的方式则工作量更大
  2. 转换后的非黑白色不好控制,且效果一般

法二:使用混合模式 mix-blend-mode: difference

Activity

  1. TrumanGu commented on Nov 30, 2019

    @TrumanGu
    TrumanGu
    on Nov 30, 2019
    More actions

    转换后有内味儿了

    Reacted by sea
  2. chokcoco commented on Nov 30, 2019

    @chokcoco
    chokcoco
    on Nov 30, 2019
    OwnerAuthor
    More actions

    @TrumanGu 还在探索中 😂

  3. hexuan-aurora commented on Mar 27, 2020

    @hexuan-aurora
    hexuan-aurora
    on Mar 27, 2020
    More actions

    可以通过 Media Query 查询 prefers-color-scheme 属性来检测用户系统的主题。

  4. dk-plus commented on Mar 4, 2021

    @dk-plus
    dk-plus
    on Mar 4, 2021
    More actions

    可以用css atrribute+css变量来做,类似这样:
    body {--primary-color: white}
    body[theme="dark"] {--primary-color: black}
    .button: {background: var(--primary-color)}
    给body加theme="dark"就ok了

    Reacted by TwitterIsGood
  5. chokcoco
    added
    未完成
    on Mar 23, 2023
  6. Harhao commented on Feb 22, 2024

    @Harhao
    Harhao
    on Feb 22, 2024
    More actions

    可以用css atrribute+css变量来做,类似这样: body {--primary-color: white} body[theme="dark"] {--primary-color: black} .button: {background: var(--primary-color)} 给body加theme="dark"就ok了

    这个在低版本一点android的webview就存在很大问题了,不支持attribute的属性,直接挂球

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    未完成

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.