<?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: António Fernandes</title>
    <description>The latest articles on DEV Community by António Fernandes (@rock_67).</description>
    <link>https://dev.to/rock_67</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%2F197830%2F54060aac-88a8-43d2-a28d-ac8e5448e78d.jpg</url>
      <title>DEV Community: António Fernandes</title>
      <link>https://dev.to/rock_67</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rock_67"/>
    <language>en</language>
    <item>
      <title>Save time using SASS to create classes with variations</title>
      <dc:creator>António Fernandes</dc:creator>
      <pubDate>Fri, 19 Jul 2019 16:35:51 +0000</pubDate>
      <link>https://dev.to/rock_67/save-time-using-sass-to-create-classes-with-variations-59n9</link>
      <guid>https://dev.to/rock_67/save-time-using-sass-to-create-classes-with-variations-59n9</guid>
      <description>&lt;p&gt;Last week, I had a problem.&lt;/p&gt;

&lt;p&gt;I needed to define a class in HTML that would give me the margin according to the last char. But this last char wasn’t always the same, nor the place was the margin would be applied.&lt;/p&gt;

&lt;p&gt;I wanted a class that would be margin-top-1, or bottom,or left or right and the last number would go from 1 to 5 rem.&lt;br&gt;
I was using SCSS already but, I didn’t know how to do it.&lt;/p&gt;

&lt;p&gt;God knows that I searched for an answer, but still could not find how that should be done.&lt;br&gt;
Maybe I googled it wrong but I know the answer now, and I was not limited to the margin.&lt;br&gt;
Now I use this everywhere.&lt;br&gt;
Let’s see how I’ve done it.&lt;/p&gt;

&lt;p&gt;We have all been there. We need to create a class with different variations so that we can use them in HTML. Although SCSS can save us a lot of work, it is still repetitive, it’s still boring.&lt;br&gt;
Sometimes the best way to avoid repetitive tasks is by doing a repetitive function.&lt;br&gt;
How? You ask.&lt;br&gt;
Through a &lt;a class="mentioned-user" href="https://dev.to/for"&gt;@for&lt;/a&gt; directive.&lt;/p&gt;

&lt;p&gt;So let’s say that you need to define a CSS class to use in your HTML with some variables. Let’s say you wanted to define the class margin-(number) and the number would be the value in rem. Something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fygx296v5lyrhyhds5laf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fygx296v5lyrhyhds5laf.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well if you only wanted to define .margin-1 there is no need to make a loop. You can simply write it like this but, let’s say for the sake of this article that you would want to define margin all the way to the 100rem. That is the beauty of SAAS.&lt;/p&gt;

&lt;p&gt;You can define a starting point, an ending point and a &lt;a class="mentioned-user" href="https://dev.to/for"&gt;@for&lt;/a&gt; directive to iterate through the numbers.&lt;/p&gt;

&lt;p&gt;So, let’s see how does it look!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fltjbefajmwyaeutel2ff.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fltjbefajmwyaeutel2ff.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And that’s it. after you compile it, it’s like if you have written 300 + lines of code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzsxc4uwkwmb235pkjgrs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzsxc4uwkwmb235pkjgrs.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Won’t post the full CSS here because it’s too large, but you get the idea if not open your text editor and try it yourself.&lt;br&gt;
And now you can use the margin class on your HTML as you like.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fulxttlw2st8qs9tloztf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fulxttlw2st8qs9tloztf.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But what if I want to define the top or bottom or any other?&lt;br&gt;
Well, in that case, you should define the variables, and create other classes.&lt;/p&gt;

&lt;p&gt;Still can use the same directive.&lt;br&gt;
The only difference is that you need to define top, bottom, left, right and auto. But in the end, it is the same that we have done above. You can use this for everything.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fgcb8sn1orngxxyn88har.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fgcb8sn1orngxxyn88har.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here you go, with approximately 30 lines of code, you have compiled a CSS file with more than 2000 lines.&lt;/p&gt;

&lt;p&gt;And the possibilities are endless, you can use this with almost all attributes, width, height, you name it.&lt;br&gt;
Have fun!&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>saas</category>
    </item>
  </channel>
</rss>
