DEV Community

L1GEND
L1GEND

Posted on

Css Best Practices Part : 01

CSS BEST PRACTICES

1- Avoid Code Duplication : Keeping Your CSS Code Dry Will Help You Minimizing The Amount Of Edits To Make Change To A component

Css Code

2- Don't Use Absolute Lengths : Use Relative Units For Scallable Size On Larger & Smaller Viewports

Css Lengths

Example :

font-size : 24px
Enter fullscreen mode Exit fullscreen mode

Use :

font-size : 75%
Enter fullscreen mode Exit fullscreen mode

3- Use Inheritance : Use Inheritance To Copy A Specific Parameter From The Parent Element

Css Inheritance

Example :

input , select , button { font:inherit; }
Enter fullscreen mode Exit fullscreen mode

4- Use Viewport Relative Units : Use Viewport Relative Units , To Reduce The Amount Of Media Queries For Every Viewport And Keep Your Code Clean

Css Viewport Units

Example :

vh (viewHeight) vw(viewWidth) vmin , vmax
Enter fullscreen mode Exit fullscreen mode

4- Set max-width For Replaced Elements : Set Max Width For Replaced Elements Such As : img - object - video - iframe

Css Max Width

Hit The Like Button If You Like The Content
Thanks For Reading

Top comments (0)