Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dark/light images in MD #3683

Closed
jumpersdevice opened this issue Nov 4, 2020 · 2 comments
Closed

Dark/light images in MD #3683

jumpersdevice opened this issue Nov 4, 2020 · 2 comments
Labels
closed: question This issue is a user error/misunderstanding.

Comments

@jumpersdevice
Copy link

Hello,

Tried discord, search and couldn't find anything or get anyone to reply me so I though i'd post here. Can anybody explain how you use a dark image in an MD when the theme is switched to dark and automatically switch to a light version of that image when the theme is set to light?

Thanks

@jumpersdevice jumpersdevice added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Nov 4, 2020
@slorber
Copy link
Collaborator

slorber commented Nov 4, 2020

Hi,

This problem is not specific to docusaurus but is related to dark mode support in general for server-rendered apps.
On static output page, you need to choose one image URL or the other, but when page is loaded by the browser, you do not want this image to be replaced by the other variant, to avoid FOUC.

  • You can add a non-alpha opaque background to your image
  • You can try to convert it to svg and read css variables of the theme to color it
  • You can append 2 images in the html, and use CSS queries to display one or the other
  • You can render the image only on the client, based on theme, with the BrowserOnly docusaurus component

@slorber
Copy link
Collaborator

slorber commented Nov 4, 2020

Example using CSS to conditionnally display one of 2 images according to current theme:

html[data-theme='dark'] img.light {
   display: none;
}

html[data-theme='light'] img.dark {
   display: none;
}

This is pseudo-code, can't guarantee it will work but it's worth trying

@Josh-Cena Josh-Cena added closed: question This issue is a user error/misunderstanding. and removed bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Mar 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed: question This issue is a user error/misunderstanding.
Projects
None yet
Development

No branches or pull requests

3 participants