Since 2019, both Android and IOS platforms have begun to play Dark Mode. Of course, there is nothing wrong with this, but when our page is turned on by the user in dark mode, the traditional big white will instantly be blinded by the eyes.
Here I will briefly talk about how to make the page support dark mode.
PrepareIn fact, we just need to use the preferreds-color-scheme media query in css.
HTML
<!DOCTYPE html><html lang=en><head> <meta charset=UTF-8> <meta name=viewport content=width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no> <title>Page adapts to dark mode</title></head><body class=back><div class=models><h1>Test text</h1></div></body></html>
CSS
.back {background: white; color: #555;text-align: center}@media (prefers-color-scheme: dark) { .back {background: #333; color: white;} .models {border:solid 1px #00ff00}}@media (prefers-color-scheme: light) { .back {background: white; color: #555;} .models {border:solid 1px #2b85e4}}The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.