Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 3167

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 26, 20242024-11-26T12:11:07+00:00 2024-11-26T12:11:07+00:00

Auto Enabling dark mode(CSS only)πŸŽ‰πŸŽ‰

  • 61k

Hey There, Most of the users(specially developers) are the huge fan of dark mode and try to use it on all apps and software. They will definitely expect enabling dark mode on web content also. So, we can get their theme preference by their OS(In this blog, technically call as “UA” means User Agent) without need to toggle😲😲.

Dark mode is better for your eyes in low-light environments and is better for your device battery.

We can achieve these without asking help to JavaScriptπŸŽ‰ which really sounds good (Disclaimer: I'm not mean JS is complicated, But we enable these feature as simple as possible). Seems be like,
Image description
NO, I'm not kiddingπŸ˜…. Seriously possible.

A magical media queryπŸͺ„

Using @media (prefers-color-scheme: dark) media query, We can detect if the user has requested a light or dark color theme by User Agent(based on OS settings).

For instance,

  @media (prefers-color-scheme: dark) {   :root {     --main-bg-color: #040404;     --card-bg-color: #3a3a38;     --icon-bg-color: #f7d1a2;     --main-light-onColor: #aeb4bd;     --main-dark-onColor: #777676;   } }  /* we can also style for light mode*/ @media (prefers-color-scheme: dark) { }   
Enter fullscreen mode Exit fullscreen mode

Above instance illustrate that,

  • If OS theme preference is dark, Then it will be changed to dark mode. Otherwise, It will stuck with light mode.

Image description

  • If OS theme preference is light, Then it will be changed to light mode. Image description :root Selects the root element of the document: in the case of HTML and defined the custom property inside :root means which can be declared and used globally in document. Use Custom property is a best practice which save our loads of time like Life saver.

If you not aware of Custom property, Not a big issue. I will explain, else you just skip this fold and pass on to next fold.

CSS Custom Property(Variables)

Declaring a custom property is done using a custom property name that begins with a double hyphen (–), and a property value that can be any valid CSS value.

A common best practice is to define custom properties on the :root pseudo-class, so that it can be applied globally across your HTML document.

  :root {   --main-bg-color: brown; }   
Enter fullscreen mode Exit fullscreen mode

Uh, Creating a custom property is pretty easy right. Likewise, Use this custom property is painless processπŸ˜‰. Just you use the custom property value by specifying your custom property name inside the var() function, in place of a regular property value.

For instance,

  header{ background-color: var(--main-bg-color); }   
Enter fullscreen mode Exit fullscreen mode

Hope you grasped the concept and let's get a ride on next..

Hey still with me, Proud to see your curiosity about learning new things✨. It's my pleasure to give you a bonus info and some additional resource for practice.

color-scheme – Must include

We need to add styles for even form controls, scrollbars and so on. It's may be painful process. So, Using color-scheme changes the default text and background colors of the page to match the current system appearance, standard form controls, scrollbars and other named system colors also change their look automatically.

  :root {   color-scheme: dark light; }   
Enter fullscreen mode Exit fullscreen mode

  /* possible property values */ color-scheme: normal; color-scheme: light; color-scheme: dark; color-scheme: light dark;   
Enter fullscreen mode Exit fullscreen mode

color-scheme specifying the values light and dark on the root element. let's the rendering engine known both modes are supported by the document.

I recommend you to practice on codepen or fork my repository🎁 and practice on you own pace.

If you loved this blog, Then give an endearing heartπŸ’and drop your thought about this blog😍 which really a lot to me. I love the discussion with you, If you feel not comfortable at styling concepts or have any doubts.

If you not experiment with Claymorphism, Start to explore now.

Thanks for Reading!!
Preethi
– Make your CSS life easier

csshtmltodayilearnedwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.