{"id":394,"date":"2017-08-17T05:32:23","date_gmt":"2017-08-17T05:32:23","guid":{"rendered":"http:\/\/mansainfotech.com\/blog\/?p=394"},"modified":"2017-08-17T05:32:23","modified_gmt":"2017-08-17T05:32:23","slug":"what-are-css-preprocessors","status":"publish","type":"post","link":"https:\/\/mansainfotech.com\/blog\/what-are-css-preprocessors\/","title":{"rendered":"What are CSS Preprocessors?"},"content":{"rendered":"<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">Having prior mastery over CSS, it probably becomes easy to use its preprocessors, namely \u2013 Sass, Less &amp; Stylus. <\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">Let\u2019s segregrate our learning of CSS Preprocessors into the following:<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">** CSS<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">** Preprocessors<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">** CSS Preprocessors<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">** Sass<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">** Less<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"><span style=\"color: #800000;\"><i>What is Css? <\/i><\/span>Refering to Cascading style sheets, describes how Html elements should be displayed on all screen devices. <\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">All in all, Css describes layouts, positioning, width, height and alignment of webpages. It saves lot of work with its ability to write once and run anywhere. For more on Css, check out my previous post &#8211; <\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"><span style=\"color: #800000;\"><i>What is Preprocessor? <\/i><\/span>It is a kind of program which takes one type of data and converts down it to another type of data. For instance, Haml is processed into Html and Sass is processed into Css. <\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">Now, let\u2019s get down to <span style=\"color: #800000;\"><i>What are Css preprocessors? <\/i><\/span>It is a scripting language which extends Css and then compiles down it to regular Css. <\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">Using Css became quite complex and repetitive for accomplishing little tasks such as closing tags, so, that is where css preprocessors comes into picture. As developer wanted more options when writing their styles, so, they built preprocessors for adding programming functionality. <\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"><span style=\"text-decoration: underline;\">Salient features: <\/span><\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">&#8211; Arithmatics i.e. addition, substraction, multiplication, division<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">&#8211; Variables<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">&#8211; Functions<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">&#8211; If &amp; else conditions<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">&#8211; Looping<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">&#8211; Mixins<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">&#8211; Extends<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">&#8211; Color operations<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">&#8211; Imports, etc.<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"><span style=\"text-decoration: underline;\">Pros and Cons of using Css Preprocessors:<\/span><\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"><span style=\"text-decoration: underline;\">Pros<\/span><\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">&#8211; Cleaner code<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">&#8211; Saves you huge time<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">&#8211; Easy to setup<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">&#8211; More organized<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">&#8211; Faster development<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"><span style=\"text-decoration: underline;\">Cons<\/span><\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">&#8211; Learning curve<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">&#8211; While working in a team&#8230;<\/span><\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">&#8211; And, too much of everything is a con (nesting, mixing)<\/span><\/span><\/p>\n<p class=\"western\" style=\"text-align: center;\" align=\"center\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"><b>Sass Preprocessor<\/b><\/span><\/span><\/p>\n<hr \/>\n<p class=\"western\" align=\"justify\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">Sass is Ruby based Css extension. For running Sass, you need to have ruby installed. You can install sass with this command &#8211; <\/span><\/span><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">sudo gem install sass<\/span><\/span><\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">. <\/span><\/span><\/code><\/p>\n<p class=\"western\" align=\"justify\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">Once sass is installed, you can run it with the command sass input.scss output.css from your terminal. <\/span><\/span><\/code><\/p>\n<p class=\"western\" align=\"justify\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">Let\u2019s understand \u2018Sass\u2019 by taking instances of variables,nesting and loops. <\/span><\/span><\/code><\/p>\n<p class=\"western\" align=\"justify\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"><span style=\"text-decoration: underline;\">Variables in Sass<\/span><\/span><\/span><\/code><\/p>\n<pre class=\"western\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">$font-size: 14px;<\/span><\/span><\/code>\n\n<code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">div {<\/span><\/span><\/code>\n<code class=\"western\">    <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">font-size: $font-size;<\/span><\/span><\/code>\n<code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">}<\/span><\/span><\/code><\/pre>\n<p class=\"western\" align=\"justify\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"><span style=\"text-decoration: underline;\">Nesting in Sass<\/span><\/span><\/span><\/code><\/p>\n<pre class=\"western\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">$link-color: #000;<\/span><\/span><\/code>\n<code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">ul {<\/span><\/span><\/code>\n<code class=\"western\">    <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">margin: 0;<\/span><\/span><\/code>\n<code class=\"western\">    <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">li {<\/span><\/span><\/code>\n<code class=\"western\">        <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">float: left;<\/span><\/span><\/code>\n<code class=\"western\">    <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">}<\/span><\/span><\/code>\n<code class=\"western\">    <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">a {<\/span><\/span><\/code>\n<code class=\"western\">        <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">color: $link-color;<\/span><\/span><\/code>\n<code class=\"western\">    <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">}<\/span><\/span><\/code>\n<code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">}<\/span><\/span><\/code><\/pre>\n<p class=\"western\" align=\"justify\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"><span style=\"text-decoration: underline;\">Loops in Sass<\/span><\/span><\/span><\/code><\/p>\n<pre class=\"western\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">@for $i from 1px to 5px {<\/span><\/span><\/code>\n<code class=\"western\">    <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">.border-#{i} {<\/span><\/span><\/code>\n<code class=\"western\">        <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">border: $i dotted green;<\/span><\/span><\/code>\n<code class=\"western\">    <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">}<\/span><\/span><\/code>\n<code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">}<\/span><\/span><\/code><\/pre>\n<p class=\"western\" style=\"text-align: center;\" align=\"center\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"><b>Less Preprocesor<\/b><\/span><\/span><\/code><\/p>\n<hr \/>\n<p class=\"western\" align=\"justify\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">Since Less is written in Javascript, so, you will need NodeJS to run it. Install Less using <\/span><\/span><\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"><span style=\"text-decoration: underline;\">npm install -g less<\/span><\/span><\/span><\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"> on Linux\/Mac and use <\/span><\/span><\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"><span style=\"text-decoration: underline;\">lessc styles.less styles.css<\/span><\/span><\/span><\/code><code class=\"western\"> <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">to compile it to Css.<\/span><\/span><\/code><\/p>\n<p class=\"western\" align=\"justify\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">On windows, you first need to install Node.Js installer followed by:<\/span><\/span><\/code><\/p>\n<p class=\"western\" align=\"justify\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">1. <\/span><\/span><\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">npm install less<\/span><\/span><\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"> (install)<\/span><\/span><\/code><\/p>\n<p class=\"western\" align=\"justify\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">2. <\/span><\/span><\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">lessc styles.less styles.css<\/span><\/span><\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"> (compile)<\/span><\/span><\/code><\/p>\n<p class=\"western\" align=\"justify\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">Here also, let\u2019s understand \u2018Less\u2019 by taking examples of variables, nesting and loops. <\/span><\/span><\/code><\/p>\n<p class=\"western\" align=\"justify\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"><span style=\"text-decoration: underline;\">Variables in Less<\/span><\/span><\/span><\/code><\/p>\n<pre class=\"western\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">@font-size: 14px;<\/span><\/span><\/code>\n<code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">div {<\/span><\/span><\/code>\n<code class=\"western\">    <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">font-size: @font-size;<\/span><\/span><\/code>\n<code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">}<\/span><\/span><\/code><\/pre>\n<p class=\"western\" align=\"justify\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"><span style=\"text-decoration: underline;\">Nesting in Less<\/span><\/span><\/span><\/code><\/p>\n<pre class=\"western\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">@link-color: #000;<\/span><\/span><\/code>\n<code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">ul {<\/span><\/span><\/code>\n<code class=\"western\">    <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">margin: 0;<\/span><\/span><\/code>\n<code class=\"western\">    <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">li {<\/span><\/span><\/code>\n<code class=\"western\">        <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">float: left;<\/span><\/span><\/code>\n<code class=\"western\">    <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">}<\/span><\/span><\/code>\n<code class=\"western\">    <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">a {<\/span><\/span><\/code>\n<code class=\"western\">        <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">color: @link-color;<\/span><\/span><\/code>\n<code class=\"western\">    <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">}<\/span><\/span><\/code>\n<code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">}<\/span><\/span><\/code><\/pre>\n<p class=\"western\" align=\"justify\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"><span style=\"text-decoration: underline;\">Loops in Less<\/span><\/span><\/span><\/code><\/p>\n<pre class=\"western\"><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">.loop(@counter) when (@counter &gt; 0){<\/span><\/span><\/code>\n<code class=\"western\">    <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">.loop((@counter - 1));<\/span><\/span><\/code>\n<code class=\"western\">    <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">.border-@{counter} {<\/span><\/span><\/code>\n<code class=\"western\">        <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">border: 1px * @counter dotted green;<\/span><\/span><\/code>\n<code class=\"western\">    <\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">}<\/span><\/span><\/code>\n<code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\">}\n<\/span><\/span><\/code>\n<code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"><span style=\"text-decoration: underline;\">Let\u2019s Conclude our journey into Css preprocessors:<\/span><\/span><\/span><\/code><code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"> If you are technical and coming from programming background, then Css is very powerful and streamlined. Sass is more widely used beside Less, with rich set of features. All this makes Css highly extensible, maintainable and themeable. <\/span><\/span><\/code>\n\n<code class=\"western\"><span style=\"font-family: verdana,sans-serif;\"><span style=\"font-size: medium;\"><b>Please comment down your view points on my small post concerning #preprocessors_of_css. I\u2019d love to hear and answer you!\n\n<\/b><\/span><\/span><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Having prior mastery over CSS, it probably becomes easy to use its preprocessors, namely \u2013 Sass, Less &amp; Stylus. Let\u2019s segregrate our learning of CSS Preprocessors into the following: ** CSS ** Preprocessors ** CSS Preprocessors ** Sass ** Less What is Css? Refering to Cascading style sheets, describes how &hellip; <a href=\"https:\/\/mansainfotech.com\/blog\/what-are-css-preprocessors\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">What are CSS Preprocessors?<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":401,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[],"class_list":["post-394","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-design-and-development"],"_links":{"self":[{"href":"https:\/\/mansainfotech.com\/blog\/wp-json\/wp\/v2\/posts\/394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mansainfotech.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mansainfotech.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mansainfotech.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mansainfotech.com\/blog\/wp-json\/wp\/v2\/comments?post=394"}],"version-history":[{"count":0,"href":"https:\/\/mansainfotech.com\/blog\/wp-json\/wp\/v2\/posts\/394\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mansainfotech.com\/blog\/wp-json\/wp\/v2\/media\/401"}],"wp:attachment":[{"href":"https:\/\/mansainfotech.com\/blog\/wp-json\/wp\/v2\/media?parent=394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mansainfotech.com\/blog\/wp-json\/wp\/v2\/categories?post=394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mansainfotech.com\/blog\/wp-json\/wp\/v2\/tags?post=394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}