admin管理员组文章数量:1287489
I'm building an app where I display emails on it. I have no control over those emails, so I don't know what their CSS looks like.
Is there any "easy" way to automatically switch the whole HTML to dark mode, whenever possible?
Just like Gmail does when your device has Dark Mode enabled.
I'm using React Native and Expo, displaying the HTML through WebView, in case it's of any help. Thanks!
I'm building an app where I display emails on it. I have no control over those emails, so I don't know what their CSS looks like.
Is there any "easy" way to automatically switch the whole HTML to dark mode, whenever possible?
Just like Gmail does when your device has Dark Mode enabled.
I'm using React Native and Expo, displaying the HTML through WebView, in case it's of any help. Thanks!
Share Improve this question asked Oct 8, 2020 at 5:28 Franco MuñizFranco Muñiz 9211 gold badge10 silver badges22 bronze badges2 Answers
Reset to default 14I personally tend to respect the email's CSS and keep them as-is.
There's no easy way to get perfect result, since the "dark mode" is not well defined concept, and depends on the actual CSS of specific content.
But a rough solution is quite cheap. Just apply the CSS filter: invert(100%)
to whole HTML.
@media (prefers-color-scheme: dark) {
html {
filter: invert(100%);
}
/* double apply invert filter to cancel out effect on images */
img {
filter: invert(100%);
}
}
Here's an easy way to switch back and forth between light and dark mode:
javascript:(function(){
document.documentElement.style.filter = document.documentElement.style.filter ? '' : 'invert(100%)'
})();
Copy/paste in your browser on any website to test.
本文标签: javascriptConvert any HTML to Dark ModeStack Overflow
版权声明:本文标题:javascript - Convert any HTML to Dark Mode - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741308230a2371497.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论