DEV Community

Shirin Monzavi
Shirin Monzavi

Posted on

๐Ÿš€ ๐’๐ญ๐จ๐ฉ ๐ซ๐ž๐ฉ๐ž๐š๐ญ๐ข๐ง๐  @๐ฆ๐ž๐๐ข๐š ๐ฌ๐œ๐ซ๐ž๐ž๐ง! ๐”๐ฌ๐ž ๐’๐š๐ฌ๐ฌ ๐Œ๐ข๐ฑ๐ข๐ง๐ฌ ๐ญ๐จ ๐ฆ๐š๐ค๐ž ๐ฒ๐จ๐ฎ๐ซ ๐ซ๐ž๐ฌ๐ฉ๐จ๐ง๐ฌ๐ข๐ฏ๐ž ๐‚๐’๐’ ๐œ๐ฅ๐ž๐š๐ง๐ž๐ซ ๐š๐ง๐ ๐ฌ๐ฆ๐š๐ซ๐ญ๐ž๐ซ.

๐๐ซ๐จ๐›๐ฅ๐ž๐ฆ?
Assume, you are styling a responsive web application. When styling for different screen sizes, you often need to write multiple @media queries. This can lead to repeating @media statements throughout your CSS file. How can we avoid it?

๐’๐จ๐ฅ๐ฎ๐ญ๐ข๐จ๐ง?
Sass solves this problem by Mixin. Mixins allow you to define styles that can be re-used throughout your stylesheet.

๐‡๐จ๐ฐ?
๐Ÿ’  Install Sass โ†’ npm install sass.

๐Ÿ’ Define a mixing named it screen-style with the argument of size screen and in the body use @content (take an entire block of styles).

๐Ÿ’ Define a new mixin named it small-breakpoint and use name of previous mixin with @include (it will be included in the previous mixin).

๐Ÿ’ Define the desired selector.

๐Ÿ’ Use the small-breakpoint mixin with @include inside the selector.

๐Ÿ’ Add the desired styles.

โ“ ๐‡๐š๐ฏ๐ž ๐ฒ๐จ๐ฎ ๐ž๐ฏ๐ž๐ซ ๐ฎ๐ฌ๐ž ๐Œ๐ข๐ฑ๐ข๐ง๐ฌ? ๐ˆ๐Ÿ ๐ฌ๐จ, ๐’๐ก๐š๐ซ๐ž ๐ฒ๐จ๐ฎ๐ซ ๐ž๐ฑ๐ฉ๐ž๐ซ๐ข๐ž๐ง๐œ๐ž ๐ข๐ง ๐ญ๐ก๐ž ๐œ๐จ๐ฆ๐ฆ๐ž๐ง๐ญ.

hashtag#CSS hashtag#Sass hashtag#FrontendDevelopment hashtag#WebDevelopment hashtag#CleanCode

Top comments (0)