Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Ajith kannan
Ajith kannan

Posted on

     

Themes

Hello folks, Let's see the journey of mine with the Themes. Whenever we create a new theme, we have to deal with CSS. So again we are going to write the same CSS with different colors and it makes the code repetitive like the following Script.

Light Theme

product .light-theme {   background-color: white;   color: blue;}product .light-theme:hover {   background-color: blue;   color: white;}

Dark Theme

product .dark-theme {   background-color: black;   color: white;}product .dark-theme:hover {   background-color: white;   color: black;}

For the optimization, Custom Properties play a major role in this CSS. Interesting..?

So what is Custom Properties ?

Custom Property is a pre-defined variable and it stores the value of the CSS property.

Okay, Then how it gonna be optimized?

Whenever we update the variable (Custom Property)within the scope, it automatically update the values of property which used the same variable (Custom Property).

Pretty Cool ?

Lets see the code,

:root{  --libg : white;  --licolor : black;  --borderleft : blue;  --libghover : #e1e1e8;  --lihovercolor : blue;}.sidebar {  width: 220px;  .light {    li {      background-color : var(--libg);      color : var(--licolor);      border-left : 5px solid var(--borderleft);      &:hover {        background-color : var(--libghover);        color : var(--lihovercolor);      }    }  }}

Dark theme made by Custom Variable

.sidebar {  .dark {  --libg : #151f2a;  --licolor : white;  --borderleft : blue;  --libghover : black;  --lihovercolor : white;  }}

Final Thoughts

  1. Redundant CSS reduced.
  2. Easy to customize.
  3. No need to track the CSS properties.

Hope you figure out the concept well. Let's see you on another journey. Thanks for reading.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Read next

bobcars profile image

Unveiling Lucent Public License 1.02: A Balanced Approach to Fair Code

Bob Cars(on) -

jennythomas498 profile image

Unveiling the Legacy: A Deep Dive into the IBM PowerPC Initialization and Boot Software License

JennyThomas498 -

abhishek-dave-008 profile image

Risks to CI/CD Secrets in Over 23,000 Repositories and Implications for Software Supply Chain Security

Abhishek Dave -

githubopensource profile image

Misconfig Mapper: Your New Secret Weapon for Cloud Security

GitHubOpenSource -

I'm a passionate developer
  • Location
    India
  • Work
    Frontend Developer at Zoho
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp