<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[Hello, I'm Matt Fairbrass]]></title><description><![CDATA[UX Developer & Designer from London, England. Based in Sydney, Australia.]]></description><link>http://mattfairbrass.com/</link><generator>Ghost 0.6</generator><lastBuildDate>Thu, 16 Apr 2026 10:07:03 GMT</lastBuildDate><atom:link href="http://mattfairbrass.com/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[CSS 360° no scope]]></title><description><![CDATA[SydCSS Dec 2015 presentation]]></description><link>http://mattfairbrass.com/2015/12/03/sydcss-dec-2015/</link><guid isPermaLink="false">ab8929e6-14bc-4bcb-9cb1-37b1541db29f</guid><dc:creator><![CDATA[Matt Fairbrass]]></dc:creator><pubDate>Thu, 03 Dec 2015 06:28:46 GMT</pubDate><media:content url="http://mattfairbrass.com/content/images/2015/12/syd-css-dec-2015-02.jpg" medium="image"/><content:encoded><![CDATA[<img src="http://mattfairbrass.com/content/images/2015/12/syd-css-dec-2015-02.jpg" alt="CSS 360° no scope"><p>At the <a href="http://www.meetup.com/SydCSS/events/226855511">December 2015 SydCSS meetup</a> I gave a talk on local scope in CSS, which I have <a href="http://mattfairbrass.com/2015/08/17/css-achieving-encapsulation-scope">written about</a> previously.</p>

<p>In the talk I discuss a few techniques we can use today to achieve encapsulation in CSS, including build tools like <a href="https://github.com/css-modules/css-modules">CSS Modules</a> with <a href="https://webpack.github.io">Webpack</a>, and examine the future specifications of the language (CSS4) which aim at introducing local scope.</p>

<ul>
<li><strong>Slides:</strong> <a href="http://matt-d-rat.github.io/deck-css-360-no-scope">http://matt-d-rat.github.io/deck-css-360-no-scope</a></li>
<li><strong>Webpack &amp; CSS Modules demo:</strong> <a href="https://github.com/matt-d-rat/css-360-no-scope-webpack-demo">https://github.com/matt-d-rat/css-360-no-scope-webpack-demo</a></li>
</ul>

<iframe src="http://matt-d-rat.github.io/deck-css-360-no-scope" width="100%" height="480" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:1px solid #CCC; border-width:1px; margin-bottom:5px; max-width: 100%;" allowfullscreen></iframe>]]></content:encoded></item><item><title><![CDATA[Quick Tip: Git Aware Prompt]]></title><description><![CDATA[Show your current git branch in your terminal prompt]]></description><link>http://mattfairbrass.com/2015/08/31/git-aware-prompt/</link><guid isPermaLink="false">0e3abcba-22e3-46fe-b169-3693b9698808</guid><category><![CDATA[git]]></category><category><![CDATA[quicktip]]></category><category><![CDATA[terminal]]></category><category><![CDATA[git-aware-prompt]]></category><dc:creator><![CDATA[Matt Fairbrass]]></dc:creator><pubDate>Mon, 31 Aug 2015 04:44:00 GMT</pubDate><content:encoded><![CDATA[<p><a href="https://github.com/jimeh/git-aware-prompt">Git Aware Prompt</a> is a really useful shell script written by <a href="https://github.com/jimeh">Jim Myhrberg</a> that displays your current git branch in the terminal prompt, saving you the hassle of having to type <code>git status</code> every time.</p>

<p><img src="http://mattfairbrass.com/content/images/2015/08/git-aware-prompt.png" alt="Screenshot of git-aware-prompt"></p>

<p>As you can see from the screenshot above, my current branch is displayed in parenthesis in blue, and when I change branch, the branch name in the prompt updates as well.</p>

<h2 id="installgitawareprompt">Install Git Aware Prompt</h2>

<p>Create a <code>.bash</code> directory in the root of your user directory if  one doesn't already exist, change directory and clone the project:</p>

<pre><code class="language-git">mkdir ~/.bash  
cd ~/.bash  
git clone git://github.com/jimeh/git-aware-prompt.git  
</code></pre>

<p>Now edit your <code>.bash_profile</code> located in the root of your user directory:</p>

<pre><code class="language-git">vim ~/.bash_profile  
</code></pre>

<p>and add the following lines and save the changes:</p>

<pre><code class="language-git">export GITAWAREPROMPT=~/.bash/git-aware-prompt  
source "${GITAWAREPROMPT}/main.sh"  
</code></pre>

<h2 id="configuration">Configuration</h2>

<p>Now that everything is installed, all that's left to do is to configure how we want our terminal to display this information. Below is an example configuration (the configuration I used in the screenshot above), but feel free to customise this to your liking.</p>

<p>Add the configuration for your OS to your <code>~/.bash_profile</code>:</p>

<h3 id="macosx">Mac OSX</h3>

<pre><code class="language-git">export PS1="\u@\h \W \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "  
</code></pre>

<h3 id="ubuntu">Ubuntu</h3>

<p><strong>Standard:</strong></p>

<pre><code class="language-git">export PS1="\${debian_chroot:+(\$debian_chroot)}\u@\h:\w \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "  
</code></pre>

<p><strong>Colorised:</strong></p>

<pre><code class="language-git">export PS1="\${debian_chroot:+(\$debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "  
</code></pre>

<h3 id="windows">Windows</h3>

<pre><code class="language-git">export PS1="\[\033]0;$MSYSTEM:\w\007\033[32m\]\u@\h:\[\033[33m\w \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\033[0m\]\$ "  
</code></pre>

<p>That's it! Restart the Terminal app if it's currently running (or source your bash_profile to load the changes), and change directory to a git initialised project to see the results.</p>

<p>Checkout the instructions on the <a href="https://github.com/jimeh/git-aware-prompt">Git Aware Prompt</a> project for more configuration options.</p>]]></content:encoded></item><item><title><![CDATA[Push-to-deploy with Git]]></title><description><![CDATA[Automating your deployment with Git Hooks]]></description><link>http://mattfairbrass.com/2015/08/25/push-to-deploy-to-production-with-git/</link><guid isPermaLink="false">5b52d7c3-fbf7-47e7-a714-619d22da34c9</guid><category><![CDATA[git]]></category><category><![CDATA[deployment]]></category><category><![CDATA[hook]]></category><category><![CDATA[production]]></category><category><![CDATA[remote]]></category><dc:creator><![CDATA[Matt Fairbrass]]></dc:creator><pubDate>Tue, 25 Aug 2015 07:40:36 GMT</pubDate><media:content url="http://mattfairbrass.com/content/images/2015/08/git-push-to-deploy-cover-1.jpg" medium="image"/><content:encoded><![CDATA[<img src="http://mattfairbrass.com/content/images/2015/08/git-push-to-deploy-cover-1.jpg" alt="Push-to-deploy with Git"><p>In the past, deploying changes to production was as simple as uploading the edited files with an FTP client. But with the modern complex applications we build for the web today, often as part of a distributed team, deploying to production in this manner simply isn't fit for purpose.</p>

<p>So what's the solution? Spend thousands of dollars on a deployment solution? No. Chances are if you had that sort of cash then you would already be doing that.</p>

<p>If you already use Git as your version control software, we can leverage some of Git's more powerful and perhaps lesser used features to automate deployments to a remote server.</p>

<p>In this article I will introduce you to <strong>Git bare repositories</strong> and <strong>Git hooks</strong>, specifically the <strong>post-receive</strong> hook, and show you how you can use them together to automate deployment to a remote server.</p>

<h2 id="prerequisites">Prerequisites</h2>

<p>This article assumes you're already familiar with the basics of Git and how to use it via the terminal/command line. This article also assumes you're familiar with basic terminal commands and how to access a remote server via SSH.</p>

<p>The instructions in this article are for a remote server running on Ubuntu 14.04, and a local dev machine running Mac OSX Yosemite 10.10.3, but they should also work for other OS's with a little tweaking. Both environments should already have Git installed on them, if they do not, please install Git before continuing.</p>

<p>Finally, please ensure you make backups of your data before following this guide. I accept no responsibility for any loss of data, misconfiguration or damage otherwise caused. <em>Sigh</em>, it's a sad world we live in when we have to cover ourselves legally, but there you have it. Right, on with the guide!</p>

<h2 id="introductiontogithooks">Introduction to Git hooks</h2>

<p>Git hooks are event driven, when certain events happen as a result of an action, such as pushing code, Git checks a series of hooks to see if there is an associated script to run.</p>

<p>Some scripts run prior to an action taking place, which can be used to ensure code compliance to standards, for sanity checking, or to set up an environment. Other scripts run after an event in order to deploy code, re-establish correct permissions (something git cannot track very well), and so forth.</p>

<p>Using these abilities, it is possible to enforce policies, ensure consistency, and control your environment, and even handle deployment tasks.</p>

<h3 id="gitpostreceivehook">Git post-receive hook</h3>

<p>This is run on the remote when pushing after the all refs have been updated. It does not take parameters, but receives info through stdin in the form of <code>&lt;old-value&gt; &lt;new-value&gt; &lt;ref-name&gt;</code>. Because it is called after the updates, it cannot abort the process.</p>

<p>What this allows us to do is for us to <code>git push</code> our local changes to production, and have Git on the server handle the deployment for us through a script that checks out the changes.</p>

<h2 id="gitbarerepository">Git bare repository</h2>

<p>Since we will never be directly editing the files checked out on the remote server, and nor shouldn't we, we will be using a bare repository instead of a working repository.</p>

<h3 id="whatsthedifferencebetweenabarerepoandaworkingrepo">What's the difference between a bare repo and a working repo?</h3>

<p>Jon Saints sums this up nicely in his article <a href="http://www.saintsjd.com/2011/01/what-is-a-bare-git-repository">'What is a bare git repository?'</a>:</p>

<blockquote>
  <p>Repositories created with the <code>git init</code> command are called <strong>working directories</strong>. In the top level folder of the repository you will find two things:</p>
  
  <ul>
  <li>A .git subfolder with all the git related revision history of your repo.</li>
  <li>A working tree, or checked out copies of your project files.</li>
  </ul>
  
  <p>Repositories created with <code>git init --bare</code> are called <strong>bare repos</strong>. They are structured a bit differently from working directories:</p>
  
  <p>First off, they contain no working or checked out copy of your source files. And second, bare repos store git revision history of your repo in the root folder of your repository instead of in a .git subfolder.</p>
</blockquote>

<p>So in essence, a working repository is for <strong>working</strong>, and a bare repository is for <strong>sharing</strong>.</p>

<p>The way in which we will be using a bare repository is by configuring Git to store the Git related revision history in a <strong>not-publicly</strong> web accessible folder, as this most likely contains sensitive information, and to checkout our project files into a separate <strong>publicly</strong> web accessible directory so that are project can be viewed.</p>

<h2 id="configuringtheremoteserverfordeployment">Configuring the remote server for deployment</h2>

<p>Now that we understand a bit more about Git hooks and Git bare repositories we can start to configure our remote server for push-to-deploy deployments.</p>

<h3 id="initialiseagitbarerepository">Initialise a Git bare repository</h3>

<p>Start off by <code>SSH</code>ing into your remote server and creating a directory in your <strong>user directory</strong>. This directory will be used to hold our git bare repository:</p>

<pre><code class="language-git">$: mkdir ~/myproject.git
$: cd ~/myproject.git
$: git init --bare
</code></pre>

<p>
<em>Note:</em> the '.git' suffix to the folder name is just a convention and is not necessary.</p>

<p>This initialises the bare repository, and all of the files that would otherwise be stored in a <code>.git</code> hidden folder in a working repository are stored at the root of this folder.</p>

<h3 id="createapostreceivehook">Create a post-receive hook</h3>

<p>Next we need to setup the script that will run as part of the <strong>post-receive hook</strong>. Open up the following file in a text editor:</p>

<pre><code class="language-git">$: vim hooks/post-receive
</code></pre>

<p>So what do we need this script to do? When we push changes to the remote we want Git to checkout those changes to a <strong>publicly accessible</strong> folder in our web server's web root.</p>

<p>We can achieve this by adding the following lines:</p>

<pre><code class="language-git">#!/bin/bash
git --work-tree=/var/www/myproject --git-dir=/home/matt/myproject.git checkout -f  
</code></pre>

<p>Let's look at this command in more detail:</p>

<ul>
<li><strong>--work-tree flag:</strong> specifies the directory to checkout our project's working files to, in this case a publicly accessible folder in the Apache web root: <code>/var/www/myproject</code>.</li>
<li><strong>--git-dir flag:</strong> specifies the git directory path for the project, in this case the bare repository we created in the last step in our user directory: <code>/home/matt/myproject.git</code></li>
</ul>

<p>This is great, but if we left the script as it currently stands, <strong>any</strong> branch that is pushed to the remote will be checked out. We need to add some logic to ensure that the only branch that can be pushed is <code>master</code> (or what ever branch you have designated as representing what is in production).</p>

<p>Fortunately as we learnt earlier, Git provides information about the change through <code>stdin</code> in the form of <code>&lt;old-value&gt; &lt;new-value&gt; &lt;ref-name&gt;</code>. We can use this to determine the reference for the change, ie: that it was the <code>master</code> branch that was pushed:</p>

<p>Add the following logic check to the <strong>post-receive</strong> hook:</p>

<pre><code class="language-git">#!/bin/bash
while read oldrev newrev ref  
do  
    if [[ $ref =~ .*/master$ ]];
    then
        git --work-tree=/var/www/myproject --git-dir=/home/matt/myproject.git checkout -f
    fi
done  
</code></pre>

<p>Let's break down what is going on in this code. First we read the <code>stdin</code> with a <code>while</code> loop, receiving three pieces of information (old rev, new rev, ref), separated by white space, for each ref.</p>

<p>Next we check for a <code>master</code> branch push by checking the <code>$ref</code> object for a reference that contains something like <code>refs/heads/master</code> via the <code>if</code> logical check.</p>

<p>This ensures that only changes being pushed from the <code>master</code> branch to the remote will be applied.</p>

<p>Seeing as for server-side hooks Git is able to pass messages back to the connected client, we will add some <code>stdout</code> to inform the user of what is happening:</p>

<pre><code class="language-git">#!/bin/bash
while read oldrev newrev ref  
do  
    if [[ $ref =~ .*/master$ ]];
    then
        echo "Master ref received.  Deploying master branch to production..."
        git --work-tree=/var/www/myproject --git-dir=/home/matt/myproject.git checkout -f
    else
        echo "Ref $ref successfully received.  Doing nothing: only the master branch may be deployed on this server."
    fi
done  
</code></pre>

<p>That's it for the script. Save and close when you're finished.</p>

<p>Now that we have written our post-receive hook we need to make it executable so that Git can run it:</p>

<pre><code class="language-git">$: chmod +x hooks/post-receive
</code></pre>

<h2 id="configuringourlocalmachine">Configuring our local machine</h2>

<p>On your development machine change directory into your project's working directory:</p>

<pre><code class="language-git">$: cd /path/to/myproject
</code></pre>

<p>Next we will add a new <code>remote</code> to git called <code>production</code>. For this you will need to know the following information:</p>

<ul>
<li>The <strong>username</strong> that is used for your production server.</li>
<li>The <strong>IP address</strong> or <strong>domain</strong> for the production server.</li>
<li>The location of the bare repository you set up in relation to the user's home directory.</li>
</ul>

<p>The command you'll run should look something like this:</p>

<pre><code class="language-git">$: git remote add production matt@server_domain_or_IP:myproject.git
</code></pre>

<p>That's it. You can now successfully deploy your master branch to your remote server by running the following command:</p>

<pre><code class="language-git">$: git push production master
</code></pre>

<p><em>Note: If you have not configured SSH keys, you may be prompted to enter your password.</em></p>

<p>Upon running the command above, you should see something similar to the following output in your terminal window:</p>

<pre><code class="language-git">Counting objects: 8, done.  
Delta compression using up to 2 threads.  
Compressing objects: 100% (3/3), done.  
Writing objects: 100% (4/4), 473 bytes | 0 bytes/s, done.  
Total 4 (delta 0), reused 0 (delta 0)  
remote: Master ref received.  Deploying master branch...  
To matt@xxx.xxx.xxx.xxx:myproject.git  
   009183f..f1b9027  master -&gt; master
</code></pre>

<p>If we try to push a branch other than <code>master</code> to production, then you will see the following:</p>

<pre><code class="language-git">$: git checkout feature/test-branch
$: git push production feature/test-branch
</code></pre>

<pre><code class="language-git">Counting objects: 5, done.  
Delta compression using up to 2 threads.  
Compressing objects: 100% (2/2), done.  
Writing objects: 100% (3/3), 301 bytes | 0 bytes/s, done.  
Total 3 (delta 1), reused 0 (delta 0)  
remote: Ref refs/heads/feature/test-branch successfully received.  Doing nothing: only the master branch may be deployed on this server  
To matt@xxx.xxx.xxx.xxx:myproject.git  
   83e9dc4..5617b50  feature/test-branch -&gt; feature/test-branch
</code></pre>

<p>Notice the remote's post-receive hook executed the <code>else</code> block on our logical check, resulting in no changes being applied.</p>

<h2 id="conclusion">Conclusion</h2>

<p>As we have demonstrated in this article, it is possible to setup a sophisticated deployment mechanism with Git.</p>

<p>You can expand on the topics covered in this article further; adding remote post-receive hooks to other environments, allowing you to push code to a staging server for testing prior to pushing to production.</p>

<p>You can also extend this script to run other commands, such as installing package dependencies, or configuring the application prior to being deployed. The possibilities are endless.</p>

<p>The real benefit though is the automation this technique brings. As we have demonstrated we have removed some of the human error from the process, and streamlined what would otherwise be a tedious and repetitive task.</p>]]></content:encoded></item><item><title><![CDATA[Local Scope in CSS]]></title><description><![CDATA[Faux local scope in the CSS global scope]]></description><link>http://mattfairbrass.com/2015/08/17/css-achieving-encapsulation-scope/</link><guid isPermaLink="false">e1c64dce-db9f-4e8a-8331-43a56824005a</guid><category><![CDATA[css]]></category><category><![CDATA[suitcss]]></category><category><![CDATA[scope]]></category><category><![CDATA[encapsulation]]></category><category><![CDATA[bem]]></category><category><![CDATA[shadow dom]]></category><category><![CDATA[css-modules]]></category><dc:creator><![CDATA[Matt Fairbrass]]></dc:creator><pubDate>Tue, 18 Aug 2015 03:46:19 GMT</pubDate><media:content url="http://mattfairbrass.com/content/images/2015/08/css-scope-cover-1.jpg" medium="image"/><content:encoded><![CDATA[<img src="http://mattfairbrass.com/content/images/2015/08/css-scope-cover-1.jpg" alt="Local Scope in CSS"><p>When building applications for the web at scale, the need for a proper scope and encapsulation in CSS is becoming ever more apparent, without it our applications are fragile to change, and the house of cards that is CSS can quickly come crashing down around us.</p>

<p>In this article I'll be examining some of the techniques we can use today to achieve encapsulation, and taking a look to the future with  the currently proposed specifications that introduce scope at a language level.</p>

<h1 id="whatisscopeandwhyisitsoimportant">What is scope and why is it so important?</h1>

<p><a href="https://en.wikipedia.org/wiki/Encapsulation_(computer_programming)">Encapsulation</a>, or scope, is often taken for granted, most programming languages support encapsulation in some form, be it through the use of classes in an object-orientated language architecture, or through the use of <a href="https://en.wikipedia.org/wiki/Closure_(computer_programming)">lexical closures</a> in languages with first-class functions.</p>

<p>The use of encapsulation or scoping allows us to shape our application architecture by:</p>

<ul>
<li>Restricting access to some of the components implementation, allowing us to define a clear interface</li>
<li>Facilitate the bundling of data with the methods (or other functions) operating on that data</li>
<li>Avoid namespace collisions or accidentally overriding another part of the application by a later declaration</li>
</ul>

<p>The last point is probably the most relevant when it comes to CSS. </p>

<h1 id="cssglobalscope">CSS global scope</h1>

<p>In CSS everything exists in the global scope. Declarations that come later can override other rules that have been previously declared.</p>

<p>The problem is further compounded by the language where by rules that are <a href="https://medium.com/@dte/understanding-css-selector-specificity-a02238a02a59">more specific will take precedence over rules that are less specific</a>.</p>

<pre><code class="language-css">/* The background color will be red */
.foo.bar {
    background-color: red;
}

.foo {
    background-color: blue;
}

.bar {
    background-color: green;
}
</code></pre>

<p>This problem often arises when using third-party CSS libraries, where by the library styles can end up overriding the CSS rules for your project, even though your stylesheets are declared later.</p>

<h1 id="techniquesforachievingscopeincss">Techniques for achieving scope in CSS</h1>

<h2 id="languagedesignmethodologies">Language Design Methodologies</h2>

<p>While CSS provides the ability to declare styles that cascade, it's often advantageous now a days to not use this feature of the language, as you'll find it difficult to scale a project as the complexity grows.</p>

<p>One approach for achieving a sort of "pseudo encapsulation" in CSS is through the use of language design methodologies, such as <a href="https://en.bem.info">BEM</a> or <a href="http://mattfairbrass.com/2015/05/05/suit-css">SUIT CSS</a>.</p>

<p>In essence a language design methodology defines a set of rules for how to write CSS. These rules are enforced through linters and pre-compilers, which will break the build if this convention is not followed. In the case of BEM and SUIT CSS the language design methodology is taken a step further through a style that conveys a semantic meaning, while maintaining a set of shallow declarations that are additive by nature.</p>

<p>For example, in SUIT CSS you may declare a set of styles as follows:</p>

<pre><code class="language-css">.MyComponent {}
.MyComponent-descendent {}
.MyComponent--modifier {}
.MyComponent.is-state {}
</code></pre>

<p>As you'll notice, the styles are flat and the only combination selector is one that defines a components state.</p>

<p>These rules can optionally be prefixed with a namespace for the project for further encapsulation, this is especially useful if you are sharing a set of core styles between multiple projects or applications.</p>

<p>The advantage of writing CSS in this manner is that each component is responsible for defining how it looks, and the design encourages you to compose larger features from smaller components. The CSS in this design pattern is <strong>scoped to the component</strong>, and styles are <strong>not leaked into the global scope</strong>.</p>

<p>However, this still doesn't avoid the issue of namespace collision when using third-party libraries, and problems can still arise because this is still a manual process, which is fairly tedious, repetitive and prone to human error.</p>

<h2 id="precompilerscoping">Pre-compiler scoping</h2>

<p>As JavaScript workflows have trended towards building collections of components, CSS workflows have followed suit. However, any progress on the CSS front has been purely conventional, as seen by the language design methodologies above, and are not directly supported by the language itself.</p>

<p>One of the fundamental features of the <a href="http://webpack.github.io/docs/loaders.html">Webpack loader</a> (which is also core to <a href="http://jspm.io">JSPM</a> and easily possible with <a href="http://browserify.org">Browserify</a>) is the ability to explicitly describe each file's dependencies regardless of the type of source file. For CSS in a component workflow, that takes the following form:</p>

<pre><code class="language-javascript">// Marks the CSS as being a dependency of this JS.
// Depending on the loader, the CSS is either injected
// into the DOM or bundled into a separate CSS package.
require( './my-component.css' );  
module.exports = function() {  
    // component definition
};
</code></pre>

<p>Now, whenever <strong><em>my-component.js</em></strong> is loaded or bundled, the corresponding CSS is guaranteed to be present, just like any other dependency. This convention leads us to a new capability, and necessitates a new specification, enter <a href="https://github.com/css-modules/css-modules">css-modules</a>.</p>

<h3 id="cssmodules">css-modules</h3>

<p>With css-modules we can emulate local scope and control dependencies in front-end components. By default, all class names and animation names are scoped locally. All URLs <code>url(...)</code> and <code>@imports</code> are in module request format.</p>

<p>For example, say I have the following styles declared for a component:</p>

<pre><code class="language-css">/* my-component.css */

.root {}
.image {}
.description {}
</code></pre>

<p>When css-modules processes this CSS file, it will automatically prefix each class selector making it <strong>globally unique</strong>. To apply these classes in our template we <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import">import</a> (or <a href="http://requirejs.org/docs/commonjs.html">require</a>) it into a js file:</p>

<blockquote>
  <p>Note: At the time of writing, you will need a build step for this part since most browsers don’t support import / require statement natively yet. There are css-modules implementations for <a href="https://github.com/webpack/css-loader">webpack</a>, <a href="https://github.com/css-modules/css-modulesify">browserify</a> and <a href="https://www.npmjs.com/package/jspm-loader-css-modules">jspm</a> to handle this part.</p>
</blockquote>

<pre><code class="language-javascript">// ES6
import styles from './my-component.css'  
</code></pre>

<pre><code class="language-javascript">// CommonJS
var styles = require('./my-component');  
</code></pre>

<p>Behind the scenes, css-modules exports the classnames of our stylesheets as an object, which gets assigned to the styles variable declared in the import statement of our js file.</p>

<p>We can then use this object in our templates to output the classnames in the correct parts of the DOM of our component:</p>

<pre><code class="language-markup">&lt;!-- using ES6 string literals --&gt;  
&lt;div class="${styles.root}"&gt;  
    &lt;img class="${styles.image}" src="path/to/image.png" /&gt;
    &lt;p class="${styles.description}"&gt;Lorem ipsum&lt;/p&gt;
&lt;/div&gt;  
</code></pre>

<pre><code class="language-markup">&lt;!-- using AngularJS (one-time binding) --&gt;  
&lt;div class="{{::styles.root}}"&gt;  
    &lt;img class="{{::styles.image}}" src="path/to/image.png" /&gt;
    &lt;p class="{{::styles.description}}"&gt;Lorem ipsum&lt;/p&gt;
&lt;/div&gt;  
</code></pre>

<p>Looking at the rendered HTML, you'll notice the classnames that are output is similar to the code we wrote in our CSS, except we have avoided any accidental namespace collision because css-modules has prefixed our component with a namespace.</p>

<pre><code class="language-markup">&lt;div class="_myComponent__root"&gt;  
    &lt;img class="_myComponent__image" src="path/to/image.png" /&gt;
    &lt;p class="_myComponent__description"&gt;Lorem ipsum&lt;/p&gt;
&lt;/div&gt;  
</code></pre>

<p>This means that we can avoid namespace collisions by also running third-party libraries through the same css-modules processor, prefixing them with a unique global namespace, and because the process is automatic, it is less prone to human error.</p>

<p>There are also lots of other cool features that css-modules provides such as composition, which I will be covering in a later article.</p>

<h2 id="cssscopepseudoclass">CSS :scope pseudo-class</h2>

<p>Defined as part of the <a href="http://www.w3.org/TR/selectors4/#scope-pseudo">W3C CSS Selectors Level 4 (working draft) specification</a>, the :scope pseudo-class provides scoping to CSS at a language level by representing any element that is in the contextual reference element set. A scoped <code>&lt;style&gt;</code> element is used to "scope" a selector so that it only matches within a subtree.</p>

<p>So what does this all mean? It means that instead of hanging styles off of the <code>:root</code> context, which by default is the <code>&lt;html&gt;</code> tag, we can declare a separate <code>:scope</code> context that is attached to a specified DOM subtree, all child elements of this subtree will be styled according to the scoping of the CSS, and sibling elements and their children will remain unaffected.</p>

<p>So with this information in mind lets illustrate this further with an example:</p>

<pre><code class="language-markup">&lt;style&gt;  
    p {
        color: black;
    }
&lt;/style&gt;

&lt;p&gt;I will be coloured black.&lt;/p&gt;

&lt;section&gt;  
    &lt;style scoped&gt;
        p {
            color: red;
        }
    &lt;/style&gt;
    &lt;p&gt;I will coloured red because my styles are scoped!&lt;/p&gt;
&lt;/section&gt;

&lt;p&gt;I will also be coloured black.&lt;/p&gt;  
</code></pre>

<p>As you can see, the <code>&lt;style&gt;</code> tag is given the <code>scoped</code> attribute, this creates a new scope context, hanging off of the parent element, which in this example is the <code>&lt;section&gt;</code> element. All children of the <code>&lt;section&gt;</code> element will receive the new styling rules, and will be styled accordingly.</p>

<p>We can also <code>@import</code> an external CSS file and scope it like so:</p>

<pre><code class="language-markup">&lt;div&gt;  
    &lt;style scoped&gt;
        @import 'path/to/stylesheet/main.css';
    &lt;/style&gt;
&lt;/div&gt;  
</code></pre>

<h2 id="cssscopeatrule">CSS @scope at-rule</h2>

<p>One criticism of the CSS :scope pseudo-class is that we are back to mixing HTML and inline-styles again, and I am inclined to agree, I don't like to use inline <code>&lt;style&gt;</code> tags because more often than not you end up repeating yourself, the code is harder to maintain and I cannot leverage my favourite CSS pre-compiler anymore.</p>

<p>The <a href="http://www.w3.org/TR/css-scoping-1/#at-ruledef-scope">@scope at-rule</a> allows authors to create scoped style rules using CSS syntax, where the elements matched by the <code>&lt;selector&gt;</code> are scoping roots for the style rules in the <code>&lt;stylesheet&gt;</code>, and selectors of style rules scoped by @scope are scope-contained to their scoping root.</p>

<p>For example:</p>

<pre><code class="language-css">span {  
    color: black;
}

@scope div {
    span {
        color: red;
    }
}

@scope section {
    span {
        color: green;
    }
}
</code></pre>

<p>By default all spans on a page (which are attached to the :root scope context) will be coloured black, while spans inside of the div and section <code>@scope</code> context will be coloured red and green respectively.</p>

<p>This simple example illustrates how to create isolated scopes in CSS, the easiest way to think about it is to view the <code>@scope</code> at-rule as being similar to the <code>@media</code> at-rule, in that, the styles are conditionally applied given the context. Styles will not bleed outside of this context.</p>

<p>Importantly, styles that are declared after cannot affect rules that are scoped. For instance in the following example, the colour of the <code>&lt;p&gt;</code> element text will be red.</p>

<pre><code class="language-css">@scope aside {
    p { 
        color: red; 
    }
}

aside#sidebar p {  
    color: black; 
}
</code></pre>

<p>Even though the ruleset for <code>aside#sidebar p</code> is more specific, because <code>aside</code> is scoped, only the rules declared inside that scope context will be applied.</p>

<p>In the case of both the <code>:scope</code> pseudo-class and the <code>@scope</code> at-rule, at the time of writing, both are currently in a state of working draft proposals, so <a href="http://caniuse.com/#feat=style-scoped">browser support</a> is very light, and in the case of Google Chrome the feature was partially implemented behind an experimental flag and then later <a href="https://www.chromestatus.com/features/5374137958662144">removed due to code complexity</a>, favouring instead the next feature for discussion, the Shadow DOM.</p>

<h2 id="shadowdom">Shadow DOM</h2>

<p>The <a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components/Shadow_DOM">Shadow DOM</a> is a method of establishing and maintaining functional boundaries between DOM trees and how these trees interact with each other within a document, thus enabling better functional encapsulation within the DOM.</p>

<p>Unlike language design methodologies or pre-compiler scoping, which only emulate a local scope, the Shadow DOM provides us with an actual local scope for a component, and not just for CSS either, but for the HTML and JavaScript too!</p>

<p>At the time of writing though, <a href="http://caniuse.com/#feat=shadowdom">browser support</a> is light, and browsers who do support the feature normally have it turned off by default behind an experimental feature flag.</p>

<p>For example, if I had the following markup and JavaScript the output would be as follows:</p>

<iframe height="268" scrolling="no" src="http://mattfairbrass.com//codepen.io/matt-d-rat/embed/pJBmvQ/?height=268&theme-id=12596&default-tab=result" frameborder="no" allowtransparency="true" allowfullscreen="true" style="width: 100%;">See the Pen <a href="http://codepen.io/matt-d-rat/pen/pJBmvQ/">Shadow DOM example</a> by Matt Fairbrass (<a href="http://codepen.io/matt-d-rat">@matt-d-rat</a>) on <a href="http://codepen.io">CodePen</a>.  
</iframe>

<p>Note that if the JavaScript asks for the <code>host.textContent</code>, the output would be <code>Hello World</code> instead of <code>Lorem Ipsum</code>, this is because the DOM subtree under the shadow root is encapsulated.</p>

<h1 id="summarytldr">Summary (tl;dr)</h1>

<ul>
<li>JavaScript and CSS have made great strides towards component based workflows, however CSS at a language level is still lacking the necessary features for achieving encapsulation</li>
<li>Up until now, scope in CSS has been achieved through convention, by using language design methodologies like <a href="https://en.bem.info">BEM</a> and <a href="http://mattfairbrass.com/2015/05/05/suit-css">SUIT CSS</a></li>
<li>Pre-processor scoping tools, such as <a href="https://github.com/css-modules/css-modules">css-modules</a>, are helping to automate these conventions, reducing human error</li>
<li>The <a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components/Shadow_DOM">Shadow DOM</a> is a future specification which aims to achieve proper encapsulation for JavaScript, HTML and CSS. At the time of writing though <a href="http://caniuse.com/#feat=shadowdom">browser support</a> is light.</li>
</ul>

<p>Personally I believe that the Shadow DOM/web components are the way we should be designing and building our application architecture, and as browser support picks up this will only become more prevalent. </p>

<p>In the mean time though we (unlucky few) still have to support legacy browsers, which unfortunately means we are unable to take advantage of these future specifications today. That being said, projects like <a href="https://github.com/css-modules/css-modules">css-modules</a> are closing the gap between the future and today, and leveraging them will enable us to write decoupled, more maintainable code, that will scale as our architecture grows.</p>]]></content:encoded></item><item><title><![CDATA[Thinking outside the box model]]></title><description><![CDATA[Scaling CSS in large real-time applications]]></description><link>http://mattfairbrass.com/2015/06/04/sydcss-scaling-css/</link><guid isPermaLink="false">ce82c48d-f7a1-4b2e-98a8-f27e35cd9a44</guid><dc:creator><![CDATA[Matt Fairbrass]]></dc:creator><pubDate>Thu, 04 Jun 2015 06:02:30 GMT</pubDate><media:content url="http://mattfairbrass.com/content/images/2015/06/sydcss-mattfairbrass-dark.jpg" medium="image"/><content:encoded><![CDATA[<img src="http://mattfairbrass.com/content/images/2015/06/sydcss-mattfairbrass-dark.jpg" alt="Thinking outside the box model"><p>At the <a href="http://meetup.com/SydCSS/events/222332226">June 2015 SydCSS meetup</a> I gave a five minute lightning talk on scaling CSS in large real-time applications. During this talk, I discuss some of the techniques we use at <a href="http://www.lab49.com">Lab49</a> to achieve scalability in CSS.</p>

<h2 id="video">Video</h2>

<iframe width="100%" height="424" style="border:1px solid #CCC; border-width:1px; margin-bottom:5px; max-width: 100%;" src="https://www.youtube.com/embed/BY98e5pA_gc" frameborder="0" allowfullscreen></iframe>

<h2 id="slides">Slides</h2>

<iframe src="https://www.slideshare.net/slideshow/embed_code/key/LxfTTtoW6qnVU3" width="100%" height="580" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:1px solid #CCC; border-width:1px; margin-bottom:5px; max-width: 100%;" allowfullscreen></iframe>]]></content:encoded></item><item><title><![CDATA[SUIT CSS]]></title><description><![CDATA[Suit up, because your stylesheets are going to be LEGEN…wait for it…DARY!]]></description><link>http://mattfairbrass.com/2015/05/05/suit-css/</link><guid isPermaLink="false">5ecde81a-4e5a-48b5-975d-18fe20a0b921</guid><category><![CDATA[css]]></category><category><![CDATA[suitcss]]></category><category><![CDATA[dev]]></category><dc:creator><![CDATA[Matt Fairbrass]]></dc:creator><pubDate>Wed, 06 May 2015 02:43:57 GMT</pubDate><media:content url="http://mattfairbrass.com/content/images/2015/05/cover-suitcss.jpg" medium="image"/><content:encoded><![CDATA[<img src="http://mattfairbrass.com/content/images/2015/05/cover-suitcss.jpg" alt="SUIT CSS"><p>CSS has evolved and changed much since its initial release {[{'1996-12-17' | age}]} years ago. Its introduction ushered in a new era of separation of concerns, keeping document content and its presentation separate from one another. Since then we have enjoyed a myriad of advancements in the language as it tries to keep pace with the ever changing design landscape of the web. But there is one area of the language that hasn't changed, the very foundation at the core of CSS, the cascading nature of the language.</p>

<p>As we strive to build applications that are ever increasing in complexity, the need for encapsulation is now greater than ever.</p>

<p>In this article I will be looking at <a href="https://suitcss.github.io">SUIT CSS</a>, "a styling methodology for component-based UI development". I will be looking at the goals and the naming conventions of the methodology, the build and linting tools available, and above all else, why you should be adopting SUIT CSS on your projects today!</p>

<h2 id="whatissuitcss">What is SUIT CSS?</h2>

<p>At its core, SUIT CSS is a language design pattern for CSS. Its focus is towards the development of reusable component-driven UI elements, that are semantic and encapsulated by nature, and maintain a presentational relationship between the nodes represented in the DOM without coupling the presentation to a specific DOM structure.</p>

<p>Released under the an <a href="https://github.com/suitcss/suit/blob/master/LICENSE.md">MIT licence</a> by <a href="https://twitter.com/necolas">Nicholas Gallager</a> in <a href="https://twitter.com/necolas/status/481143384275300352">June 2014</a>, SUIT CSS leverages the ideas first introduced in <a href="https://en.bem.info">BEM</a> (another web development methodology) in having semantically meaningful class names which are able to express how a component is structured, its presentation modifications, and its state.</p>

<h3 id="overviewofsuitcss">Overview of SUIT CSS</h3>

<pre><code class="language-css">.ComponentName {}
.ComponentName--modifierName {}
.ComponentName-descendentName {}
.ComponentName.is-stateOfComponent {}

.u-utilityName {}
</code></pre>

<p>What makes SUIT CSS really powerful are the subtleties that the language form semantically communicates. Lets break down each of these ideas:</p>

<h4 id="components">Components</h4>

<pre><code class="language-css">.ComponentName {}
</code></pre>

<p>Components in SUIT CSS are written in <strong>pascal case</strong> giving them a clear semantic separation from all other rule definitions. The class name will sit at the root node of the component itself.</p>

<pre><code class="language-markup">&lt;aside class="SideDrawer"&gt;...&lt;/aside&gt;  
</code></pre>

<p>If your library is going to be consumed by public projects, it is recommended that you prefix your component names with a namespace, written in <strong>lower case</strong>:</p>

<pre><code class="language-css">.namespace-ComponentName {}
</code></pre>

<h4 id="modifiers">Modifiers</h4>

<pre><code class="language-css">.ComponentName--modifierName {}
</code></pre>

<p>Modifiers, denoted by a prefixed double dash (--), are written in <strong>camel case</strong> and form the suffix of the component to be modified, or the component descendent to be modified.</p>

<p>Their use is reserved for altering the base styles of a component in some form. They must always be used <strong>in addition</strong> to the base component class (multi-class pattern):</p>

<pre><code class="language-markup">&lt;button class="Button Button--primary"&gt;...&lt;/button&gt;  
</code></pre>

<h4 id="descendants">Descendants</h4>

<pre><code class="language-css">.ComponentName-descendentName {}
</code></pre>

<p>A component descendent is a class that is attached to a descendent node of a component. <strong>It's responsible</strong> for applying presentation <strong>directly to the descendent</strong> on behalf of the component. Descendent names must be written in camel case and are prefixed with a single dash (-).</p>

<pre><code class="language-markup">&lt;aside class="SideDrawer"&gt;  
    &lt;a href="#" class="SideDrawer-link"&gt;...&lt;/a&gt;
&lt;/aside&gt;  
</code></pre>

<p>Unless absolutely necessary, descendent classes should not communicate their depth in a component. This would otherwise couple the styles to a particular DOM structure, so you want to avoid the following:</p>

<pre><code class="language-css">/* Bad! */
.ComponentName-descendentName-anotherDescendent-andAnotherDescendent {}

/* Good! */
.ComponentName-andAnotherDescendent {}
</code></pre>

<h4 id="componentstate">Component State</h4>

<pre><code class="language-css">.ComponentName.is-stateOfComponent {}
</code></pre>

<p>States are written in <strong>camel case</strong> as <strong>adjoining classes</strong> and should never be styled directly. This allows the same state names to be used in multiple contexts, but every component must define its own set of styles for that state, as they are scoped to the component.</p>

<pre><code class="language-markup">&lt;aside class="SideDrawer is-open"&gt;  
    &lt;a href="#" class="SideDrawer-link is-active"&gt;...&lt;/a&gt;
    &lt;a href="#" class="SideDrawer-link"&gt;...&lt;/a&gt;
    &lt;a href="#" class="SideDrawer-link"&gt;...&lt;/a&gt;
&lt;/aside&gt;  
</code></pre>

<h4 id="utilities">Utilities</h4>

<pre><code class="language-css">.u-utilityName {}
</code></pre>

<p>Utilities provide low-level structural and positional traits and can be applied to any element within a component. Utilities are prefixed with <code>u-</code> and should focus typically achieving only one thing.</p>

<pre><code class="language-markup">&lt;img src="..." class="Post-img u-alignLeft" /&gt;  
</code></pre>

<h2 id="whyisthisimportant">Why is this important?</h2>

<p>So this is all well and good, but why should you care? While SUIT CSS conveys semantic meaning to your CSS, it is so much more than that. Because the structure of your CSS is largely flat and most importantly, is encapsulated, maintenance and refactoring either the HTML or the CSS becomes a breeze, enabling you to scale your application as much as necessary.</p>

<p>Specificity wars, infamous <code>!important</code> overrides, and bleeding styles introduce so many defects and headaches in the long run, if your CSS has any of these problems, your architecture will be so much harder to maintain. Why put yourself through the pain?</p>

<h3 id="suitcssinpractice">SUIT CSS in practice</h3>

<p>Let me elaborate a little with a more detailed example. Consider the following HTML:</p>

<pre><code class="language-markup">&lt;header class="Header"&gt;  
    &lt;a href="#" class="Header-link"&gt;
        &lt;img src="..." class="Header-logo" /&gt;
    &lt;/a&gt;
    &lt;nav class="Nav Nav--topMenu Header-nav"&gt;
        &lt;a href="#" class="Nav-link is-active"&gt;...&lt;/a&gt;
        &lt;a href="#" class="Nav-link"&gt;...&lt;/a&gt;
    &lt;/nav&gt;
&lt;/header&gt;  
</code></pre>

<p>The <code>.Nav</code> component keeps its styles entirely encapsulated from the <code>.Header</code> component. The only class that creates a relationship between the two is the <code>.Header-nav</code> descendent class, which would simply be acting on the <code>.Nav</code> component in a positioning and/or structural manner.</p>

<p>If in the future we needed to refactor this code and detach the <code>.Nav</code> component from the <code>.Header</code> it would be as simple as moving the HTML out, and removing the <code>.Header-nav</code> class.</p>

<p>All other styles should in reality remain largely unchanged due to how we have encapsulated our components. </p>

<h2 id="liberateyourcss">Liberate your CSS</h2>

<p>When I first started writing my styles in SUIT CSS parlance it felt strange, almost counter intuitive. I had become so used to inheriting styles, it was hard to realise the benefits. Until it came to refactoring, that's when it clicked. </p>

<h3 id="maintenance">Maintenance</h3>

<p>What would have taken me hours of refactoring, and even longer to regression test, took minutes. I was able to make significant changes to the code base with 100% confidence that the only thing that was going to change was that particular component. It felt liberating. In the past CSS has felt like a house of cards, changing the smallest thing could cause the entire thing to come crashing down around you.</p>

<p>But what about code duplication? Computer science 101 tells us to always keep code DRY. Sure, with SUIT CSS there is potential for your code to become a little... erm, wetter, you could very well end up repeating yourself in a few places. But the wins you gain from a maintenance point of view far out weigh any negatives from code duplication in my opinion. </p>

<p>You can mitigate code duplication by using a pre-processor like <a href="http://sass-lang.com/">SASS/SCSS</a>, leveraging the <code>@extend</code> statement and utilising <code>@mixin</code> to keep your code DRYer. For example:</p>

<pre><code class="language-scss">.Button {
   ...
}

.Button--primary {
   ...
}

.Dropdown {
   @extend .Button, .Button--primary;
   ...
}
</code></pre>

<p>But what about the output size of the CSS? Won't it be much bigger/bloated? While performance should always be at the forefront of your mind when building applications, the output size of a CSS file shouldn't be the deciding factor to how you write the code in the first place. Minified file sizes do not tell the whole story, once gzipped the comparisons are no more than ~5% in difference in overall size. As Nicholas Gallagher mentions in his article <a href="http://nicolasgallagher.com/about-html-semantics-front-end-architecture/">'About HTML semantics and front-end architecture'</a>:</p>

<blockquote>
  <p>CSS developers using pre-processors don’t need to be overly concerned about a certain degree of repetition in the compiled CSS because it can lend itself well to smaller file sizes after HTTP compression. The benefits of more maintainable “CSS” code via pre-processors should trump concerns about the aesthetics or size of the raw and minified output CSS.</p>
</blockquote>

<p>And I'm inclined to agree with him. Having confidence in the code you're changing is key to a happy software cycle.</p>

<h3 id="testing">Testing</h3>

<p>The other big win we gain from encapsulating CSS by using methodologies such as SUIT CSS, is testing. Components should be tested firstly in isolation from one another and the application context. Without encapsulation and decoupling of components, this is not possible. When composing components together in the larger application context, your end-to-end tests round out the remainder of testing.</p>

<p>If we go back to the <code>.Header</code> / <code>.Nav</code> example above, where by we refactored the code to move the <code>.Nav</code> component out of the <code>.Header</code>, our tests around <code>.Nav</code> should remain unchanged, our end-to-end tests may be the only place that require updating.</p>

<p>There is also available a <a href="https://github.com/suitcss/rework-suit-conformance">Rework plugin for SUIT CSS</a> to check component style isolation.</p>

<h2 id="suitcsstools">SUIT CSS Tools</h2>

<p>While at its core SUIT CSS is a language design pattern, it also comes with a number of tools (all of which are entirely optional), that you can incorporate into your build process:</p>

<ul>
<li><a href="https://github.com/suitcss/preprocessor">CSS pre-processor</a> - A future facing pre-processor which uses W3C working spec CSS variables and module definitions</li>
<li><a href="https://github.com/suitcss/base">Style foundation</a> - A base set of styles which sit on top of a thing layer of <a href="http://necolas.github.io/normalize.css/">normalize.css</a> (also by Nicholas Gallagher)</li>
<li><a href="https://github.com/suitcss/utils">Style utilities</a> - A set of common utility classes</li>
<li><a href="https://github.com/suitcss/components">Style components</a> - A collection of high-level components</li>
<li><a href="https://github.com/suitcss/rework-suit-conformance">Encapsulation testing</a> - A standalone tool for testing CSS compliance against SUIT CSS methodology. Note: the SUIT CSS pre-processor includes this already.</li>
</ul>

<h2 id="conclusion">Conclusion</h2>

<p>Fundamentally, CSS wasn't originally designed for the types of applications we are building for the web today. Back then, the web was little more than a simple collection of web pages; table based layouts, animated marquees and the ever present under construction GIF. Who could of imagined we would be building applications for the browser, capable of streaming 4K video, audio, rendering entire 3D environments, dynamically populating the page with data from an array of input devices, such as GPS, compass, gyroscopes, web cams and more?</p>

<p>While the language has managed to keep pace with the changing design landscape and the advances in technology (just), at its core the cascading part of stylesheets creates more problems than it solves when building web applications, not just simple web pages.</p>

<p>In order to build high-quality web applications, comprised of many different components, then we simply have to have encapsulation in order to create a boundary between the code of that component and the code that will consume it. With correct presentation scope, the order in which components are loaded and composed no longer matters, and their styles do not bleed into other components of the application.</p>

<p>While the <a href="http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom/">Shadow DOM</a> will probably end up delivering this much needed encapsulation to CSS at a language level, we are still years off from being able to use it in production applications (at the time of writing only webkit enabled browsers; Chrome, Opera and Safari (excluding iOS Safari) <a href="http://caniuse.com/#search=shadow">support</a> it).</p>

<p>Until then, language design methodologies such as <a href="https://suitcss.github.io/">SUIT CSS</a> help to provide some sanity and structure to the scopeless madness. Paired with pre-compilers, linters and other build tools, today the suite of CSS tools are extremely powerful and useful, so that we are able to build complex, component-driven web applications that are able to scale <strong>today</strong>, instead of tomorrow.</p>

<h2 id="furtherreading">Further reading</h2>

<ul>
<li><a href="https://suitcss.github.io/">SUIT CSS Homepage</a></li>
<li><a href="https://github.com/suitcss/suit/tree/master/doc">SUIT CSS Documentation</a></li>
<li><a href="https://web-design-weekly.com/2014/08/20/introduction-to-suit-css/">Introduction to SUIT CSS</a></li>
<li><a href="http://nicolasgallagher.com/about-html-semantics-front-end-architecture/">About HTML semantics and front-end architecture</a></li>
<li><a href="http://nicolasgallagher.com/custom-css-preprocessing/">Custom CSS pre-processing</a></li>
<li><a href="http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom/">Shadow DOM 101</a></li>
</ul>]]></content:encoded></item><item><title><![CDATA[A look into the new design]]></title><description><![CDATA[Exploring the re-design of mattfairbrass.com]]></description><link>http://mattfairbrass.com/2015/05/03/a-look-into-the-new-design/</link><guid isPermaLink="false">4dc8efc5-d67c-4767-8304-476c67eac0d4</guid><category><![CDATA[project]]></category><category><![CDATA[design]]></category><dc:creator><![CDATA[Matt Fairbrass]]></dc:creator><pubDate>Sun, 03 May 2015 06:16:00 GMT</pubDate><media:content url="http://mattfairbrass.com/content/images/2015/05/cover-mattfairbrasscom-redesign.png" medium="image"/><content:encoded><![CDATA[<img src="http://mattfairbrass.com/content/images/2015/05/cover-mattfairbrasscom-redesign.png" alt="A look into the new design"><p>Over the past few years design trends have seemingly accelerated, moving beyond skeuomorphic design into the brave new world of flat design, where minimalism and typography sit at the core of its methodology. As a result, it was time that my blog received a design facelift of sorts. In this article, I cover the design decisions I made, the inspirations I drew from, and I take a look forward to where I see the current design trends moving towards.</p>

<p>It is important to look at these design trends not just from a visual point of view, but to understand why they have evolved in this manner; what experience are they trying to convey? Design holistically is not about pretty pixels, it runs deeper than simply just that. Every design decision aims at supporting the end user experience in some form.</p>

<h2 id="alookback">A look back</h2>

<p>Over the past few years, my blog as taken on a visual design that is dramatically different to its predecessor. The most recent of which can be seen in this screenshot from 2011:</p>

<p><img src="http://mattfairbrass.com/content/images/2015/05/mattfairbrasscom-2011-10-09-1.png" alt="A look into the new design"></p>

<p>Even back in 2011, we can see the design for mattfairbrass.com was taking a minimalist approach, bringing the content to the front and centre. But the execution of the design was somewhat disjointed, the typography and iconography wasn't consistent throughout. The design had also become bloated with content from other sources, which ultimately detracted from the main goal of the blog, the blog posts themselves.</p>

<p>In 2011, the way in which we were consuming content had dramatically shifted from the ways five years prior, mobile accessibility had become a key factor in designing for the web, and the 2011 design simply didn't cater for this.</p>

<h2 id="rethinkingthedesign">Re-thinking the design</h2>

<p>The previous iteration on the design had surfaced some key ideas I wanted to maintain in the new design. At its core I wanted the design to express a minimalistic  approach, but incorporate some of the other design ideas that have evolved over the past couple of years.</p>

<h3 id="heroimage">Hero Image</h3>

<p>One of my favourite design trends that emerged with great success is the hero image. Defined by <a href="http://en.wikipedia.org/wiki/Hero_image">Wikipedia</a> as:</p>

<blockquote>
  <p>A term used in web design for a specific type of web banner. A hero image is a large banner image, prominently placed on a web page, generally in the front and center.</p>
</blockquote>

<p><img src="http://mattfairbrass.com/content/images/2015/05/hero-image-examples-1.png" alt="A look into the new design"></p>

<p>The hero image is normally used to draw the attention of the users focus towards a call to action, supported by the product itself, or other imagery that is used to invoke a certain feeling in the user.</p>

<p>Hero images are typically full width, breaking through the normalised padding definitions of the site. This helps to separate it from the rest of the content, allowing it to deliver more impact.</p>

<p>They are used heavily by minimalistic websites, as they help to inject colour and vibrancy into pages which would other wise be awash in a black and white colour palette.</p>

<p>This was a trend I wanted to incorporate into the new design, but with a slight twist. I took inspiration from the login screen design in Mac OSX Yosemite, where by the wallpaper of the users desktop has a blur effect applied to it.  </p>

<p><img src="http://mattfairbrass.com/content/images/2015/05/mac-osx-login-screen-1.jpg" alt="A look into the new design"></p>

<p>I decided to introduce this as an animation aspect for when the user scrolled down the page, gradually blurring the image more and more as the user scrolled further down, helping to enforce the call to action to explore the content cards below.</p>

<p><img src="http://mattfairbrass.com/content/images/2015/05/mattfairbrasscom-scroll-animation-1.gif" alt="A look into the new design"></p>

<p>The blurring of the hero image brought with it its own technical challenges, which I will discuss at another time in a dedicated article.</p>

<h3 id="cards">Cards</h3>

<p><img src="http://mattfairbrass.com/content/images/2015/05/mattfairbrasscom-card-1.png#alignRight" alt="A look into the new design" title="">Another design trend that has emerged over the past year is the rise of cards. Popularised by Google in Google Now, which debuted on Android 4.1 (Jelly Bean), and since has seen wide adoption as part of their <a href="http://www.google.com/design/spec/material-design/introduction.html">Material Design</a> language, as well as by <a href="https://blog.intercom.io/why-cards-are-the-future-of-the-web/">other vendors</a>, cards aim at providing aggregated snippets of information in a consistent UI manner.</p>

<p>I adopted a card based layout for the main pages that show lists of posts. Using a container pattern that follows a masonry design (popularised by <a href="http://www.pinterest.com">Pinterest</a> in 2010), the form creates an experience of discovery, rather than one of a linear narrative.</p>

<p>The other advantage to using a card based layout for this type of content was that it would scale to any viewport size. This was key to accessibility when consuming the content on a mobile device vs a 4K display.</p>

<p>For more information on card based design, check out <a href="http://cardstack.io/">CardStack</a>, a great resource aimed at unifying the way in which card based design is executed by: </p>

<blockquote>
  <p>Building a Card Ecosystem based on Open Web technologies and Open Source ethos that fights back against rampant lock-in.</p>
</blockquote>

<h3 id="materialdesign">Material Design</h3>

<p>Having embraced cards within my new design I opted to fully adopt <a href="http://www.google.com/design/spec/material-design/introduction.html">Material Design</a> as well. This helped to anchor a number of design elements (inputs, buttons, typography etc..) in a familiar tactile reality of that of the physical world, with the flexibility of a design principle which is able to create new affordances that supercede those in the physical world, without breaking the rules of physics.</p>

<h3 id="exploringthezaxis">Exploring the Z-Axis</h3>

<p>I was really inspired by this article over on <a href="http://alistapart.com/article/the-z-axis-designing-for-the-future">A List Apart</a> which talks about the importance of designing for the third-dimension as we begin to face design challenges for an increasingly diverse array of shapes and sizes.</p>

<p>The obvious places where I have incorporated this principle is for the comment modal and share bottom sheets on the cards themselves. Modals are nothing new, but they serve an important role, allowing users to quickly interact with a card without needing to leave the exploration of other content.</p>

<p>A more subtle place I incorporated the z-axis is within the main container on each page itself. The hero image is anchored in a fixed position, as you scroll down the page the main content slides up over the top, creating a sudo-parallax effect. This subtle use of the z-axis allows me to communicate what is important at that point in time to the user.</p>

<h2 id="alooktothefuture">A look to the future</h2>

<p>No one can say with any degree of certainty the direction design for the web will take in the future, but there have been some key indicators in the latest design trends which might suggest a nod at the direction designers are going.</p>

<p>I predict the key areas we will see dramatic design improvement and focus in the coming year will be with the use of <strong>animation</strong> and the <strong>z-axis</strong>. </p>

<p>We're already seeing it with the card design paradigm, and the evolution from flat design to material design. Apple heavily revamped animations and transitions in <a href="http://en.wikipedia.org/wiki/IOS_7">iOS7</a>, expanding further with this principle in <a href="http://en.wikipedia.org/wiki/IOS_8">iOS8</a>. They also heavily use the z-axis with design elements that utilise translucency and blurring of lower layers.</p>

<p>The shift to card layouts will also continue to play a heavy influencing role. My hope from a developer point of view is that we will begin to see a set unifying API's that define how cards from one application act in another. From a designer point of view, I hope to see a unified set of design principles adopted by all card layouts that facilitate this integration, without the overall design becoming a disjointed frankenstein mess.</p>

<h2 id="conclusion">Conclusion</h2>

<p>The new design of my blog is anchored around one key element, the content. The content of any blog is <strong>the single most important thing</strong>, after all it's what adds value to the site, which would otherwise become just another domain taking up space in a server rack somewhere. </p>

<p>I wanted the content to always be front and centre to the reader, creating a more relaxed, accessible, and hopefully more enjoyable reading experience. This single goal led every single design decision, from choice of typography, colour palettes, to the right amount of negative space to use, or even how the content is going to be consumed. The design should almost melt away into the background, serving only to support the content.</p>

<p>Working on the re-design for mattfairbrass.com has reinvigorated my passion for writing, and I look forward to actively blogging more often. Here's to the next post.</p>]]></content:encoded></item></channel></rss>