<?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: Steven Roberts</title>
    <description>The latest articles on DEV Community by Steven Roberts (@matchboxhero10).</description>
    <link>https://dev.to/matchboxhero10</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%2F254682%2F52f99a28-ed07-45c2-974f-780bd188f2c7.jpg</url>
      <title>DEV Community: Steven Roberts</title>
      <link>https://dev.to/matchboxhero10</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/matchboxhero10"/>
    <language>en</language>
    <item>
      <title>Grid Tutorial - The Holy Grail (of) Layout</title>
      <dc:creator>Steven Roberts</dc:creator>
      <pubDate>Mon, 28 Oct 2019 09:47:53 +0000</pubDate>
      <link>https://dev.to/matchboxhero10/grid-tutorial-the-holy-grail-of-layout-40ef</link>
      <guid>https://dev.to/matchboxhero10/grid-tutorial-the-holy-grail-of-layout-40ef</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published in Web Designer Mag: March 2017&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Code: &lt;a href="http://codepen.io/collection/DEgogB/"&gt;http://codepen.io/collection/DEgogB/&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;The idea here is to build the holy grail layout in Grid, but obviously it needs to be responsive. In case you don't know the holy grail layout is a header, a left sidebar, content area, right sidebar and then a footer. The code to accomplish this complex layout is pretty short and really easy to follow and understand, the syntax and new properties in Grid are not only simple but somehow elegant.&lt;/p&gt;

&lt;p&gt;Just as a bonus, we've also got that much asked for feature of the footer being at the bottom of the viewport when the content isn't long enough to fill it. With a little help from the &lt;code&gt;minmax()&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;As this demo is built using Grid you may need to turn on the appropriate browser flag until Grid is fully supported.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step One - The HTML
&lt;/h2&gt;

&lt;p&gt;As always, you can't style elements that don't exist. So we have a containing &lt;code&gt;div&lt;/code&gt; with the class of &lt;code&gt;grid&lt;/code&gt; and inside that the five elements we need to create our holy grail layout, &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt;,&lt;code&gt;&amp;lt;article&amp;gt;&lt;/code&gt;,&lt;code&gt;&amp;lt;aside&amp;gt;&lt;/code&gt;x2 and &lt;code&gt;&amp;lt;footer&amp;gt;&lt;/code&gt;. Then added the class of &lt;code&gt;grid-item&lt;/code&gt; to each of the elements and added a class to the sidebars to differentiate them in the CSS. Drop in the header from the last tutorial if you like too, Grid and Flexbox get along just fine.&lt;br&gt;
(&lt;a href="http://codepen.io/matchboxhero/pen/pRLwJY"&gt;http://codepen.io/matchboxhero/pen/pRLwJY&lt;/a&gt;)&lt;/p&gt;
&lt;h2&gt;
  
  
  Step Two - Named Areas
&lt;/h2&gt;

&lt;p&gt;Jumping into the CSS we're going to start naming our elements to create a grid template. Mobile first, we will create our grid template. It's worth noting that you can have the &lt;code&gt;grid-template-areas&lt;/code&gt; property span multiple lines in your CSS to represent the rows, allowing you to literally (ASCII style) describe the layout of your grid.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.grid {
    display: grid;
    grid-template-areas:
        "header"
        "article"
        "left-sidebar"
        "right-sidebar"
        "footer"
    ;
    grid-template-columns: 1fr;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As you can see we have literally described in our template the layout we want the grid to use. We have also defined how many columns we want we setting it to &lt;code&gt;1fr&lt;/code&gt; we're saying, there is one column and it should span the whole available width. &lt;br&gt;
(&lt;a href="http://codepen.io/matchboxhero/pen/ggeRPv"&gt;http://codepen.io/matchboxhero/pen/ggeRPv&lt;/a&gt;)&lt;/p&gt;
&lt;h2&gt;
  
  
  Step Three - Responsive
&lt;/h2&gt;

&lt;p&gt;The next step is to start adding media queries to redefine the grid template at a certain breakpoint. Since we want the layout to now have two columns in the middle we need to define these. At this breakpoint we want the header to span the entire first row and the footer the last;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@media (min-width: 540px) {
  .grid {
        grid-template-areas: 
            "header header"
            "left-sidebar article"
            "right-sidebar right-sidebar"
            "footer footer"
        ;
        grid-template-columns: 1fr 2fr;
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;By repeating the name of the area Grid knows the element should span two columns, you can also do the same thing with rows. The left sidebar and article are being split into thirds, one third being applied to the sidebar and two thirds the article.&lt;br&gt;
(&lt;a href="http://codepen.io/matchboxhero/pen/VPXWmW"&gt;http://codepen.io/matchboxhero/pen/VPXWmW&lt;/a&gt;)&lt;/p&gt;
&lt;h2&gt;
  
  
  Step Four - Wow, really?
&lt;/h2&gt;

&lt;p&gt;Now we repeat the previous step but change some of the values, so at a larger breakpoint the article and sidebars will all be on the same row.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@media (min-width: 1200px) {
  .grid {
        grid-template-areas: 
            "header header header"
            "left-sidebar article right-sidebar"
            "footer footer footer"
        ;
        grid-template-columns: 1fr 3fr 1fr;
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;grid-template-areas&lt;/code&gt; property can override the order of the DOM allowing for any layout you can dream up and the ability to change and reorder it, every 50px if you want to. Please don't, but you could.&lt;br&gt;
(&lt;a href="http://codepen.io/matchboxhero/pen/KaoqGK"&gt;http://codepen.io/matchboxhero/pen/KaoqGK&lt;/a&gt;)&lt;/p&gt;
&lt;h2&gt;
  
  
  Step Five - Bonus round
&lt;/h2&gt;

&lt;p&gt;That's it, the holy grail layout built in Grid with 2 simple media-queries. Just as a bonus lets make the footer sick to the bottom of the page when there is not enough content to fill the viewport. We accomplish this by first applying a minimum height to the grid of the viewport height, that works but the header and footer are stretched vertically to fill the leftover space. We can use the minmax() function to stop the header and footer from expanding by defining the grids rows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.grid {
    min-height: 100vh;
    height: 100vh; /* required by chrome */

    grid-template-rows: 
        minmax(min-content, max-content) 
        auto 
        minmax(min-content, max-content)
    ;

}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Using the &lt;code&gt;min-content&lt;/code&gt; and &lt;code&gt;max-content&lt;/code&gt; keyword values inside the minmax() function we've told the header and footer not to grow into the available space, allowing the middle row to use all of the extra space.&lt;br&gt;
(&lt;a href="http://codepen.io/matchboxhero/pen/JELoxx"&gt;http://codepen.io/matchboxhero/pen/JELoxx&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  ALL CODE
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;header {
  grid-area: header;
}

.left {
  grid-area: left-sidebar;
}

.right {
  grid-area: right-sidebar;
}

article {
  grid-area: article;
}

footer {
  grid-area: footer;
}

.grid {
    display: grid;
    min-height: 100vh;
    height: 100vh;
    grid-template-areas:
        "header"
        "article"
        "left-sidebar"
        "right-sidebar"
        "footer"
    ;
    grid-template-columns: 1fr;
}

@media (min-width: 540px) {
  .grid {
        grid-template-areas: 
            "header header"
            "left-sidebar article"
            "right-sidebar right-sidebar"
            "footer footer"
        ;
        grid-template-columns: 1fr 2fr;
  }
}

@media (min-width: 1200px) {
  .grid {
        grid-template-areas: 
            "header header header"
            "left-sidebar article right-sidebar"
            "footer footer footer"
        ;
        grid-template-columns: 1fr 3fr 1fr;
  }
}

.grid-item {
  padding: 24px;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>css</category>
      <category>cssgrid</category>
      <category>layout</category>
    </item>
    <item>
      <title>SASS: Mixins, Loops and Functions</title>
      <dc:creator>Steven Roberts</dc:creator>
      <pubDate>Mon, 21 Oct 2019 15:49:29 +0000</pubDate>
      <link>https://dev.to/matchboxhero10/sass-mixins-loops-and-functions-59jb</link>
      <guid>https://dev.to/matchboxhero10/sass-mixins-loops-and-functions-59jb</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published in Web Designer Mag: July 2017&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Make SASS do the repetitive work for you&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SASS is powerful tool which brings many features from other programming languages into CSS — such as functions, variables and loops — as well as bringing its own intuitive features such as mixins, nesting and partials to name a few. &lt;/p&gt;

&lt;p&gt;Today we'll be creating social icons using SASS loops, mixins and functions. We'll also be utilising the powerful nesting available in SASS.&lt;/p&gt;

&lt;p&gt;We'll be creating a list in SASS to generate our social icons, the list will consist of — at first — the classname, font reference and colour — and later the tooltip. We'll be using mixins to create reusable Media Queries and creating a function to turn a pixel value into an em value, to do this we'll also be creating a variable for our base font-size.&lt;/p&gt;

&lt;p&gt;There are a number of ways to install and use SASS depending on your system and your build tooling needs — more details can be found here &lt;a href="http://sass-lang.com/install"&gt;http://sass-lang.com/install&lt;/a&gt; —  however we'll be using CodePen to compile our SASS into CSS to keep things as simple as possible.&lt;/p&gt;

&lt;p&gt;To truly harness the power of SASS and not get yourself into a mess of specificity and complexity a solid understanding of CSS is required.&lt;/p&gt;

&lt;p&gt;The particular flavour of SASS we'll be using is SCSS, meaning we'll still be using the curly braces (&lt;code&gt;{}&lt;/code&gt;) in our SASS. &lt;/p&gt;




&lt;h2&gt;
  
  
  Step One - Codepen Setup
&lt;/h2&gt;

&lt;p&gt;The first thing we'll need to do is create a new pen (&lt;a href="https://codepen.io/pen/"&gt;https://codepen.io/pen/&lt;/a&gt;) and change some of the default settings for the CSS editor in CodePen. We'll change the CSS Preprocessor to SCSS and turn on Normalize and Autoprefixer.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r1chC2fi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ii0g4b9yr3n2q5xrqrx5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r1chC2fi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ii0g4b9yr3n2q5xrqrx5.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
CodePen CSS setup&lt;/p&gt;
&lt;h2&gt;
  
  
  Step Two - HTML Setup
&lt;/h2&gt;

&lt;p&gt;Now we've set everything up we can start writing some code. Inside the HTML editor we'll create a container and a number of items inside containing the link and icon for each of our icons. The names used here will be used in our SASS list as a reference in CSS. We'll also be using the BEM naming convention for our class names.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="social__container"&amp;gt;   
    &amp;lt;div class="social__item"&amp;gt;
        &amp;lt;a target="_blank" href="..." 
            class="social__icon--twitter"&amp;gt;
            &amp;lt;i class="icon--twitter"&amp;gt;&amp;lt;/i&amp;gt;
        &amp;lt;/a&amp;gt;
    &amp;lt;/div&amp;gt;
    ...
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Step Three - Basic Styles
&lt;/h2&gt;

&lt;p&gt;Moving over to the CSS editor we'll start by including font-awesome, setting a variable for our base font-size and some basic styles for the page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@import url(http://srt.lt/w8yT8);

// Variables
$base-font-size: 16px;

// Basic Styling
body {
    font-size: $base-font-size;
    ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Step Four - Functions
&lt;/h2&gt;

&lt;p&gt;Next we'll create a basic function to turn a pixel value to an em value using our &lt;code&gt;$base-font-size&lt;/code&gt; variable. Functions in SASS are created using &lt;code&gt;@function&lt;/code&gt; followed by the name of the function and the input used to perform the function. Then inside the declaration we use &lt;code&gt;@return&lt;/code&gt; to output the value when using the function. The &lt;code&gt;#{}&lt;/code&gt; surrounding the calculation is used for interpolation (&lt;a href="http://srt.lt/g9p6Q4"&gt;http://srt.lt/g9p6Q4&lt;/a&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Functions
@function px-to-em($pixels) {
    @return #{$pixels/$base-font-size}em;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Step Five - Mixins
&lt;/h2&gt;

&lt;p&gt;Continuing on with our set-up we'll create mixins for simple mobile first media-queries utilising our &lt;code&gt;px-to-em&lt;/code&gt; function which we will pass in a px value to return an em value. &lt;/p&gt;

&lt;p&gt;Mixins are created using &lt;code&gt;@mixin&lt;/code&gt; followed by a name for the mixin. Then inside the declaration we use &lt;code&gt;@content&lt;/code&gt; to output the code we put inside the mixin when calling it later in our codebase.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@mixin viewport--large {
    @media only screen and 
        (min-width: px-to-em(1680px)) {
        @content;
    }   }
@mixin viewport--medium {
    @media only screen and 
        (min-width: px-to-em(1080px)) {
        @content;
    }   }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Step Six - SASS List
&lt;/h2&gt;

&lt;p&gt;The last step in our setup is to create a list. Lists in SASS are created using a variable, after that the exact syntax is pretty loose, accepting a wide variety of ways to define it (&lt;a href="http://srt.lt/aD5e8C"&gt;http://srt.lt/aD5e8C&lt;/a&gt;). Inside the variable we'll define the class name, unicode value and colour for each icon, separating them with a comma, inside parentheses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$icon-list: (
    vimeo "\f27d" #1ab7ea,
    twitter "\f099" #1da1f2,
    ...
    github "\f113" #333,
    rss "\f09e" #f26522
);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h3&gt;
  
  
  Blob
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Source the icons and colours&lt;/strong&gt;&lt;br&gt;
In order to find the icons unicode values in font-awesome we can use the FontAwesome cheat sheet (&lt;a href="http://fontawesome.io/cheatsheet/"&gt;http://fontawesome.io/cheatsheet/&lt;/a&gt;) and look for the values next to each icon. In order to find the correct hex code for each button we can use the BrandColors (&lt;a href="https://brandcolors.net/"&gt;https://brandcolors.net/&lt;/a&gt;) website.&lt;/p&gt;


&lt;h2&gt;
  
  
  Step Seven - Ducks in a Row
&lt;/h2&gt;

&lt;p&gt;In order for our social icons to display in row we'll add some simple CSS to each of their containers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.social__item {
    display: inline-block;
    margin-right: 0.05em;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Step Eight - Icon Style
&lt;/h2&gt;

&lt;p&gt;To minimise the amount of CSS we output we'll be using a CSS3 selector to find all classes beginning with &lt;code&gt;icon&lt;/code&gt; and create a shared style for them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[class^="icon"] {
    font-family: 'FontAwesome';
    speak: none;
    font-style: normal;
    font-weight: normal;
    font-variant: normal;
    text-transform: none;
    line-height: 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale; }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Step Nine - Style Button Backgrounds
&lt;/h2&gt;

&lt;p&gt;Using the same method we'll do the same for the buttons defining our values in &lt;code&gt;em&lt;/code&gt;, allowing us later to resize them using the container.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[class^="social__icon"] {
    font-size: 1em; width: 2em; height: 2em;
    background-color: #333;
    color: white;
    text-decoration: none;
    border-radius: 100%;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Step Ten - @each Loop for our Icons
&lt;/h2&gt;

&lt;p&gt;Now we have all our base styles we can use our list to generate the CSS specific to each icon. To create a loop in SASS we use &lt;code&gt;@each&lt;/code&gt; followed by names for each value of each item — &lt;code&gt;$icon&lt;/code&gt;,&lt;code&gt;$unicode&lt;/code&gt; and &lt;code&gt;$icon-background&lt;/code&gt; — followed by the word &lt;code&gt;in&lt;/code&gt; and then the name of the list.&lt;/p&gt;

&lt;p&gt;Inside the loop we'll apply the &lt;code&gt;$unicode&lt;/code&gt; value to the &lt;code&gt;before&lt;/code&gt; pseudo element of each icon we've created in the HTML allowing our shared style we created earlier to take care of all the other styles needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@each $icon, $unicode, $icon-background 
in $icon-list {

    .icon--#{$icon} {
        &amp;amp;::before {
            content: $unicode;
        }
    }

}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FNRzDIN0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/15eekjaptha34ckdqs3y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FNRzDIN0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/15eekjaptha34ckdqs3y.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
We've used our loop to generate the icons for each of our social icons.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 11 - @each Loop for our Background Colours
&lt;/h2&gt;

&lt;p&gt;The icons are now all working but we still have the fallback background colour. We'll add some more code to our list to fix that. Using the same method as above we'll output the &lt;code&gt;$icon&lt;/code&gt; name but this time on the &lt;code&gt;social__icon&lt;/code&gt; classes and inside that the &lt;code&gt;$icon-background&lt;/code&gt; colour.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@each $icon, $unicode, $icon-background 
in $icon-list {

    ...

    .social__icon--#{$icon} {
        background-color: $icon-background;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PSYXxR_i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8z9pjywcuy74s1f42499.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PSYXxR_i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8z9pjywcuy74s1f42499.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
We've added the background colours as well as the icons to our &lt;code&gt;@each&lt;/code&gt; loop.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 12 - Using our mixins
&lt;/h2&gt;

&lt;p&gt;Using the mixins we created earlier and because we styled the icons using &lt;code&gt;em&lt;/code&gt; values we can apply a font-size to the container and increase it using our media-query mixin using &lt;code&gt;@include&lt;/code&gt; and the name of the mixin followed by the code we want to include in the media-query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.social__container {
    font-size: 1em;

    @include viewport--medium {
        font-size: 1.5em;
    }
    @include viewport--large {
        font-size: 2em;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J_PzPpP0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/9dau58m2ci5gd9thmdv4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J_PzPpP0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/9dau58m2ci5gd9thmdv4.jpg" alt=""&gt;&lt;/a&gt;&lt;br&gt;
Using our mixins we've updated the font size of the container to change the icons size depending on the viewport width.&lt;/p&gt;


&lt;h3&gt;
  
  
  Tip
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Functions&lt;/strong&gt;&lt;br&gt;
Functions in css are used to return a value, usually after performing a calculation, functions can be used to perform common calculations, they can accept multiple input values to be used as part of the calculation inside the function. &lt;/p&gt;
&lt;h3&gt;
  
  
  In Depth
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Mixins in depth&lt;/strong&gt;&lt;br&gt;
Mixins can be defined requiring input or not — for example we could create a mixin for a simple clear fix, requiring no input at all which you can simply call is using &lt;code&gt;@include clearfix;&lt;/code&gt; — although this could also be achieved using a silent class, created using a &lt;code&gt;%&lt;/code&gt; selector and called using &lt;code&gt;@extend&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;More complicated mixins can be created requiring some input or content to be passed to them when being called — for example we could create a flexbox mixin to provide a fallback for older browsers. This mixin would take a flex grow, shrink and basis property and called using &lt;code&gt;@include flex(1,1,50%);&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;The mixin we've created as part of the tutorial is another way mixins can be used; accepting property value pairs and replicating them inside mixins contents.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JBKfyAMZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ywuvn62bffh3gotw1zzr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JBKfyAMZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ywuvn62bffh3gotw1zzr.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
This responsive typography or CSS Locking mixin is an example of how much complexity a mixin can handle &lt;a href="http://srt.lt/sTp6zP"&gt;http://srt.lt/sTp6zP&lt;/a&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  Step 13 - Interaction states and built in functions
&lt;/h2&gt;

&lt;p&gt;We can add some interactivity to our buttons by changing the background colour when the button is interacted with either using the mouse or the keyboard. Sass has a number of built in colour functions (&lt;a href="http://srt.lt/q9L1z"&gt;http://srt.lt/q9L1z&lt;/a&gt;) allowing us to take the background colour we've set in our list and mix it with black to darken the button — when interacted with.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;icon--#{$icon} {
    background-color: $icon-background;

    &amp;amp;:hover,
    &amp;amp;:focus,
    &amp;amp;:active {
        background-color: 
            mix(black, $icon-background, 15%);
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 14 - Transition the background colour
&lt;/h2&gt;

&lt;p&gt;We can also utilise the &lt;code&gt;transition&lt;/code&gt; property in CSS to animate the differences between the background colours. We could use the &lt;code&gt;all&lt;/code&gt; value but that is both expensive in terms of performance and would not allow us to transition different values at different timings and timing-functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[class^="social__icon"] {
    ...
    transition: background-color 
        150ms ease-in-out
    ;   
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 15 - Additional transition effects
&lt;/h2&gt;

&lt;p&gt;By adding a &lt;code&gt;relative&lt;/code&gt; positioning to the buttons and a top value and adding &lt;code&gt;top&lt;/code&gt; to our &lt;code&gt;transition&lt;/code&gt; property we can ready the elements for further interaction.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[class^="social__icon"] {
    position: relative;
    top: 0;
    ...
    transition: background-color 
        150ms ease-in-out, 
        top 250ms linear
    ;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 16 - Move the buttons up upon interaction
&lt;/h2&gt;

&lt;p&gt;For this interaction there's nothing specific needed to create it therefore we can add the code to the shared class. By applying a negative top value and removing the outline we have an even clearer visual cue of interaction.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[class^="social__icon"] {
    ... 
    &amp;amp;:hover,
    &amp;amp;:focus,
    &amp;amp;:active {
        outline: none;
        top: -0.25em;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 17 - Drop shadow
&lt;/h2&gt;

&lt;p&gt;We can also use the same method to create and animate a &lt;code&gt;box-shadow&lt;/code&gt; — adding a little more depth to the interaction — changing the vertical height of the shadow at the same time as the top value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;box-shadow: 
    0 0 0.25em -0.25em rgba(0,0,0,0.2);
&amp;amp;:hover,
&amp;amp;:focus,
&amp;amp;:active {
    ...
    box-shadow: 
        0 0.5em 0.25em -0.25em rgba(0,0,0,0.3);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2qcilW0U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8i5dvnhxcymjeebz01mb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2qcilW0U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8i5dvnhxcymjeebz01mb.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
Using transition properties we've animated any interaction with the buttons — moving them up, darkening the background and adding a drop shadow.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 18 - Tooltips
&lt;/h2&gt;

&lt;p&gt;We can easily add tooltips with CSS to add further clarity for our users. The first thing we'll do is to add the tooltip value to the list. Making sure to write them in quotes to allow the use of spaces if required.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$icon-list: (
    vimeo "Vimeo" "\f27d" #1ab7ea,
    twitter "Twitter" "\f099" #1da1f2,
    ...
    github "GitHub" "\f113" #333,
    rss "RSS" "\f09e" #f26522,
);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 19 - Modify the @each Loop
&lt;/h2&gt;

&lt;p&gt;Due to the addition to our list we'll need to modify our &lt;code&gt;@each&lt;/code&gt; loop to include the tooltip value (&lt;code&gt;$name&lt;/code&gt;). We can then output that name as the content of the &lt;code&gt;before pseudo&lt;/code&gt; element on our buttons.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@each $icon, $name, $unicode, 
    $icon-background in $icon-list {
    ... 

    .social__icon--#{$icon} {
        ...
        &amp;amp;::before {
            content: '#{$name}';
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 20 - Style the before pseudo element
&lt;/h2&gt;

&lt;p&gt;Now we have the name of each element displayed on the screen we need to style the element, adding a background colour, padding and other styling elements — as well as positioning the element and readying it for transitions and modifying the opacity and top values upon interaction.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;amp;::before { ...
    top: -3.5em;
    opacity: 0;
    transition: 
        top 250ms linear, opacity 150ms linear 150ms; 
}
&amp;amp;:hover, ... {  ...
    &amp;amp;::before {
        opacity: 1;
        top: -2.5em;    }   }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dxOtVylY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/xc7ttdkok89qhtrfjq0y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dxOtVylY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/xc7ttdkok89qhtrfjq0y.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
We've added some basic styles to the tooltips again adding transitions to animate them into position.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 21 - Style the after pseudo element
&lt;/h2&gt;

&lt;p&gt;We will use CSS triangles (&lt;a href="http://srt.lt/eS9a"&gt;http://srt.lt/eS9a&lt;/a&gt;) to create the bottom of our tooltips — again positioning the element readying it for transitions — by transitioning the opacity and top values at different timings, and adding a delay we get an animation consisting of the tooltip fading in and moving down into place.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;amp;::after {  ...
    top: -1.9em;
    opacity: 0;
    transition: 
        top 250ms linear, opacity 150ms linear 150ms;
}
&amp;amp;:hover, ... {  ...
    &amp;amp;::after {
        opacity: 1;
        top: -0.9em;    }   }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;CodePen Collection of tutorial steps&lt;/strong&gt;&lt;br&gt;
&lt;a href="http://srt.lt/tG2G7Z"&gt;http://srt.lt/tG2G7Z&lt;/a&gt;&lt;/p&gt;

</description>
      <category>sass</category>
      <category>beginners</category>
      <category>css</category>
    </item>
  </channel>
</rss>
