<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alina Savin</title>
    <description>The latest articles on DEV Community by Alina Savin (@alinasavin).</description>
    <link>https://dev.to/alinasavin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F680735%2Fc8caf3bd-b829-48fc-a6b9-2f193bf45d39.png</url>
      <title>DEV Community: Alina Savin</title>
      <link>https://dev.to/alinasavin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alinasavin"/>
    <language>en</language>
    <item>
      <title>CSS Preprocessors - the magic touch of Sass</title>
      <dc:creator>Alina Savin</dc:creator>
      <pubDate>Thu, 05 Aug 2021 17:33:06 +0000</pubDate>
      <link>https://dev.to/alinasavin/css-preprocessors-the-magic-touch-of-sass-40pk</link>
      <guid>https://dev.to/alinasavin/css-preprocessors-the-magic-touch-of-sass-40pk</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--H2OZho79--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dev8ixoa3pjvyta8n9r3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H2OZho79--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dev8ixoa3pjvyta8n9r3.png" alt="Superhero"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article we will be looking specifically at SASS (A popular CSS Preprocessor) and exploring some of the powerful features that it offers with examples of how they can be used.&lt;/p&gt;

&lt;h1&gt;
  
  
  Motivation for learning this technology
&lt;/h1&gt;

&lt;p&gt;If you are studying to become a front-end developer like myself and have been learning HTML and CSS, learning how to use a CSS preprocessor is your natural next step &lt;/p&gt;

&lt;h1&gt;
  
  
  What is a CSS preprocessor?
&lt;/h1&gt;

&lt;p&gt;A CSS preprocessor is a scripting language that extends CSS by allowing developers to write code in one language and then compile it into CSS. Sass is perhaps the most popular preprocessor around right now, but other well-known examples include Less and Stylus. Think of it like CSS with superpowers. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QFOuyWDO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a4uqt1dlqt2pyout80sx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QFOuyWDO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a4uqt1dlqt2pyout80sx.png" alt="Sass superhero"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What is Sass?
&lt;/h1&gt;

&lt;p&gt;Sass (which stands for 'Syntactically awesome style sheets) is an extension of CSS that enables you to use things like variables, nested rules, inline imports and more that are not available when using CSS on its own. It also helps to keep things organised and allows you to create style sheets faster.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why Sass?
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;reduce code repetition, hence increasing your productivity;&lt;/li&gt;
&lt;li&gt;solve maintainability problems;&lt;/li&gt;
&lt;li&gt;help you write reusable codes in CSS;&lt;/li&gt;
&lt;li&gt;help you to up-level your skills in Front End Development.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Set up
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;node extension, which is what I have used in React&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6rf3IxR---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qiyxgwwhzbh1j6flivgk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6rf3IxR---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qiyxgwwhzbh1j6flivgk.png" alt="node add"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;VS code extension&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Main features
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Variables
&lt;/h2&gt;

&lt;p&gt;Sass allows the use of variables that can store information you can use throughout your style sheet. SASS allows you to define a value once and reuse it throughout your code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//variables
$mainColor: #514663;
$secondaryColor: white;
$accent-color: #bf211e;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, three variables have been declared. Main, secondary and  accent colour. These variables can be used instead of specifying the colours multiple times. One of the main advantages of using this approach is the ability to quickly and efficiently make changes if needed. &lt;/p&gt;

&lt;h2&gt;
  
  
  Maps
&lt;/h2&gt;

&lt;p&gt;List of key value pairs that in a similar way as variables can be reused throughout the code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$font-weights: (
  'regular': 300,
  'medium': 500,
  'bold': 700,
);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$font-sizes: (
  'small': 1rem,
  'medium': 1.5rem,
  'large': 2rem,
  'extraLarge': 2.5rem,
);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above examples, I have declared a map for both font-sizes and font-weight that I have throughout my app. To access the values stored in the map you use the &lt;strong&gt;map-get&lt;/strong&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; font-size: map-get($font-sizes, large);
 font-weight: map-get($font-weights, bold);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also create &lt;strong&gt;functions&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@function fontSize($size-name) {
  @return map-get($font-sizes, $size-name);
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above I have created the function &lt;em&gt;fontSize&lt;/em&gt; that takes in the size-name and returns the map-get for that font size.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; h3 {
        position: absolute;
        font-size: fontSize(small);
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Mixins
&lt;/h2&gt;

&lt;p&gt;One of the advantages of using preprocessors is their ability to take complex, long-winded code and simplify it. This is where mixins come in handy! &lt;/p&gt;

&lt;p&gt;A mixin takes in parameters and returns a specific value or values. What it essentially does is allows you to create reusable chunks of CSS, hence simplifying your code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@mixin flexCenter($direction) {
  display: flex;
  align-items: center;
  flex-direction: $direction;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.portfolio {
  background-color: $secondaryColor;
  @include flexCenter(column);
  justify-content: center;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, a mixin has been used to specify the flex alignment. Instead of re-writing this code and specifying the links multiple times, you can declare the parameters and use &lt;a class="mentioned-user" href="https://dev.to/include"&gt;@include&lt;/a&gt;
 to use it where ever you want.&lt;/p&gt;

&lt;p&gt;As with the use of variables, mixins can also reduce the need for code repetition and improve productivity. SASS includes a number of other powerful features. This article has given a brief introduction to what SASS is and how it can be useful.&lt;/p&gt;

&lt;p&gt;To find out more, you can access the documentation &lt;a href="https://sass-lang.com/guide"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Thanks for reading! :)&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
