Friday, January 31, 2014

15 Powerful Social Media Tips

Social media is ever-changing and ever-growing. Of course, this is true of the internet in general, but even more so when talking about social media. Facebook, Google+, Twitter and countless others are constantly evolving and changing based on their users' reading, browsing and posting habits. Of course, this is good news. It does mean that social media will continue to be relevant in the years to come.

15 Powerful Social Media Tips

Friday, January 31, 2014

Scattered Polaroids Gallery

A flat-style Polaroid gallery where the items are scattered randomly in a container. When a specific item is selected, it will move to the middle while the other Polaroids will make space for it by moving to the sides. Optionally, an item can have a backface which will be shown by flipping the Polaroid when clicking on the current navigation dot again.

Scattered Polaroids Gallery

Monday, January 27, 2014

5 UX Tips for Designing More Usable Registration Forms

The web is crowded with UI solutions that we've inherited from the past, but are still applied because "everybody else does". It is time to reconsider all of them, but especially registration forms. When designing registration forms, keep in mind that they are for the user and the smoother the registration process, the more delighted your customers will be.

Here are some tips to make the most of registration forms.

Monday, January 27, 2014

Validation and Exception Handling: From the UI to the Backend

Sooner or later in your programming career you will be faced with the dilemma of validation and exception handling. This was the case with me and my team also. A couple or so years ago we reached a point when we had to take architectural actions to accommodate all the exceptional cases our quite large software project needed to handle. Below is a list of practices we came to value and apply when it comes to validation and exception handling.

Friday, January 24, 2014

CSS animation-fill-mode

We're always super excited to get into CSS animations because, quite frankly, they're incredibly awesome. One overlooked animation property, however, is the animation-fill-mode property. This CSS property sets the state of the end animation when the animation is not running. Here's a quick example:

Friday, January 24, 2014

Prevent common problems when writing CSS from scratch

Many times when I started writing the classes of a brand new site, I had two problems that bothered me very much: keeping the footer always at the bottom of the page - even if the page has few content - and using padding values in divs without influencing the overall width of the div.

Then I decided to always put the same basic classes on the css file, no matter what the layout would look like:

Friday, January 17, 2014

How to Make WordPress Sites Load 72.7% Faster

How to Make WordPress Sites Load 72.7% Faster

You want to know the secret to a faster WordPress website?

You and everyone else.

Wednesday, January 15, 2014

SVG Hover Effect

Tuesday, January 14, 2014

When To Use The Button Element

When To Use The Button Element
You use it when, uhm, you want a button on your page that users can click, right? Well, unfortunately it's a bit more complicated than that. It's not too bad though, let's figure it out.

It looks like this:

  Do Something

What's the most common result of clicking something on a website? Moving to a new URL, like you would clicking a link (an <a href="/example/"></a>) element).

The <button> element, by itself, can't do that. There have been various conversations about allowing "href anywhere" over the years, but nothing has came of it.

Clicking on a button does do something though, when used in its natural environment...

Button is a Form Element

Web forms have submit buttons. You might think of that like this:

<form action="/" method="post">
  <input type="submit" value="Submit">

A <button> element in a <form>, by default, behaves identically to that submit input above.

<form action="/" method="post">

However gross the UX, forms can have reset buttons as well. You can duplicate that behavior by changing the default submit type to reset.

<form action="/" method="post">
  <button type="reset">Reset</button>

Clicking that button will clear all the other inputs (and textareas) with the parent <form>.

Buttons can have content

The primary reason for using a <button> is that it has both and opening and closing (</button>) tag. Which means there can be stuff inside. A common use case would be something like:

  <img src="tiny_birthday_cake.png" alt="">

While an input can be <input type="image">, this mixed content would be hard to pull off.

As far as I can tell, there is no limit to what kind of content you can put in a button, so feel free to get real weird with it. Pseudo elements can be used too.

Let's leave styling <button>s for another day, but different browsers generally have a special style they apply to buttons. You'll want to either leave that alone so the default comes through, or remove it thoroughly so your new styling can be consistent across browsers.

Let's consider: "if a button doesn't have a meaningful href, it's a <button>"
I said recently that I enjoyed that sentiment. That's what kicked off this article for me. At the time, I was thinking of how I enjoyed the semantics of it. As in:

<a href="#0">
  I'm kinda sick of doing this for buttons.

There is no meaningful href there. The 0 is just there so it doesn't jump the page, because ID's can't start with a number.

Chances are, HTML like the above means: I'm going to make clicking that do something with JavaScript. Somehow that feels better than a <div> whatever, because you get the cursor change and whatever else default styles.

If you don't like those meaningless href's, a <button> can seem like a nice alternative. But unfortunately outside of the context of a <form>, a <button> is equally meaningless.

  Outside of a <form>, I'm just as useless.

But <button> feels better anyway

Even if a <button> doesn't do anything outside of a form without the help of JavaScript, it still feels better for things you can click that do stuff other than change pages. A bogus href link definitely doesn't feel right.

Alright. Let's insert it with JavaScript then

That's probably the best solution. If JavaScript is required for the clickable-thing to do anything at all, it might as well not even be there at all unless JavaScript runs. We can do:

// 1. Create the button
var button = document.createElement("button");
button.innerHTML = "Do Something";

// 2. Append somewhere
var body = document.getElementsByTagName("body")[0];

// 3. Add event handler
button.addEventListener ("click", function() {
  alert("did something");

You could easily have "button adding" be a part of your JavaScript workflow.

When links make more sense

If there is any kind of href you could put on that link that makes sense, by all means, use an anchor. Even if you override that behavior with JavaScript. That's progressive enhancement at it's finest. For instance:

  • A search button normally triggers a type-ahead ajax-search thingy - but the href could just point to a /search/ page.
  • A publish button triggers the the next stage of publishing something a user built - but the href could just point to a /publish/ page.
  • A thumbnail button opens a lightbox with a larger version - but the href could just point to the URL of that larger version.

If nothing makes sense, insert the button with JavaScript.

Accessibility concerns

Let's say using an anchor link does make sense. After you give yourself a nice little back-pat for being good at progressive enhancement, there is accessibility to consider as well.

You might be like, I got this!

<a href="#meaningful" class="button" role="button">
  I'm good

But you aren't out of the woods yet. MDN covers it well:

Warning: Be careful when marking up links with the button role. Buttons are expected to be triggered using the Space key, while links are expected to be triggered through the Enter key. In other words, when links are used to behave like buttons, adding role="button" alone is not sufficient. It will also be necessary to add a key event handler that listens for the Space key in order to be consistent with native buttons.

Get that? You activate links and buttons with different keys, so consider that.

Go forth and uhm, make clickable things correctly.

Sunday, January 12, 2014

Simple Responsive Grid

Simple Responsive Grid

A simple responsive grid layout with minimal markup.

<div>Simple Responsive Grid</div>
  <span class="grid">
    <div class="unit-2">Simple Responsive Grid</div>
    <div class="unit-2">Simple Responsive Grid</div>
    <div class="unit-3">Simple Responsive Grid</div>
    <div class="unit-3">Simple Responsive Grid</div>
    <div class="unit-3">Simple Responsive Grid</div>
    <div class="unit-4">Simple Responsive Grid</div>
    <div class="unit-4">Simple Responsive Grid</div>
    <div class="unit-4">Simple Responsive Grid</div>
    <div class="unit-4">Simple Responsive Grid</div>
<img src="">
  <span class="grid">
    <img class="unit-2" src="">
    <img class="unit-2" src="">
    <img class="unit-3" src="">
    <img class="unit-3" src="">
    <img class="unit-3" src="">
    <img class="unit-4" src="">
    <img class="unit-4" src="">
    <img class="unit-4" src="">
    <img class="unit-4" src="">

div {
    font-family: monospace;
    text-align: center;

div, img {
    width: 100%;
    font-size: 80%;
    margin-bottom: 10px;
    color: white;
    background-color: black; /* optional border color */
    padding: 10px; /* optional border width */
    box-sizing: border-box;

.grid {
    display: block;
    margin-left: -10px;

.unit-2, .unit-3, .unit-4 {
    float: left;
    border-left: 10px solid transparent;
    box-sizing: border-box;
    background-clip: padding-box;

.unit-2 { width: 50%; }
.unit-3 { width: 33.3%; }
.unit-4 { width: 25%; }

via CSS Deck by

Sunday, January 12, 2014

Character Count

Character Count

Character count for textarea with alert and cut-off. Based on experiment by Jason Saba.

<div class="wrapper">
  <h1>Textarea Character Count</h1>
  <textarea name="the-textarea" id="the-textarea" maxlength="140" placeholder="Enter Your Text Here"></textarea>
  <div id="the-count">
    <span id="current">0</span>
    <span id="maximum">/ 140</span>

<script class="cssdeck" src="//"></script>

@import url(,400,700,300italic);

*, *:before, *:after { box-sizing: border-box; }
html { font-size: 100%;  }
body { 
  font-family: 'Open Sans', sans-serif;
  font-size: 16px;
  background: tomato;
  color: #fff;

.wrapper {
  max-width: 65%;
  margin: auto;

h1 { 
  color: #fff; 
  margin: 3rem 0 1rem 0; 
  padding: 0;
  font-size: 1.5rem;
  font-family: 'Open Sans', sans-serif;
  font-weight: 400;
  display: block;
  text-align: Center;

textarea {
  width: 100%;
  min-height: 100px;
  resize: none;
  border: 1px solid #ddd;
  outline: none;
  padding: 0.5rem;
  color: #666;
  box-shadow: inset 0 0 0.25rem #ddd;
  &:focus {
    outline: none;
    border: 1px solid darken(#ddd, 5%);
    box-shadow: inset 0 0 0.5rem darken(#ddd, 5%);
  &[placeholder] { 
    font-style: italic;
    font-size: 0.875rem;

#the-count {
  float: right;
  padding: 0.1rem 0 0 0;
  font-size: 0.875rem;

$('textarea').keyup(function() {
  var characterCount = $(this).val().length,
      current = $('#current'),
      maximum = $('#maximum'),
      theCount = $('#the-count');

  /*This isn't entirely necessary, just playin around*/
  if (characterCount < 70) {
    current.css('color', '#fff');
    current.css('font-weight', 'normal');
  if (characterCount > 70 && characterCount < 90) {
    current.css('color', '#eee');
    current.css('font-weight', 'normal');
  if (characterCount > 90 && characterCount < 100) {
    current.css('color', '#793535');
    current.css('font-weight', 'normal');
  if (characterCount > 100 && characterCount < 120) {
    current.css('color', '#841c1c');
    current.css('font-weight', 'normal');
  if (characterCount > 120 && characterCount < 139) {
    current.css('color', '#8f0001');
    current.css('font-weight', 'bold');
  if (characterCount == 140) {
    maximum.css('color', '#8f0001');
    current.css('color', '#8f0001');
  } else {

Friday, January 10, 2014

Where the best designers go to find photos and graphics

find photos and graphics

I'll let you in on a little secret: beautiful websites aren't made, they're found. Smart designers know where to find that perfect photo, subtle pattern or that unique icon.

Here's where the best designers go to find photos, graphics, icons and more.

Stunning Photography

Photography is what separates a good website from a great website. There may be no better example of great photography than Apple's website. Apple loves to showcase products with huge, eye popping photography. It's a great example of how to use photos.

Here's where the best designers find photos:

  • New Old Stock Photos - Awesome vintage photos from public archives. Completely free of known copyright restrictions.
  • New Old Stock Photos
  • Super Famous - Lots of geological, biological and aerial photography from from Dutch interaction designer Folkert Gorter. Sound boring? It's not. These photos are one of a kind.
  • Unsplash - A free email newsletter stuffed with hi-resolution photos. Sent every ten days.
  • Little Visuals - Another free email newsletter. Sends weekly batches of 7 gorgeous photos.
  • Comp Fight - The fastest way to find Creative Commons images to use on your blog or website.
  • Pic Jumbo - Big, searchable database of totally free to use photos.

Sample photo from Pic Jumbo

Sharp Icons

The next time you're browsing Facebook, Google or Twitter, take note of how many icons you'll see. They're everywhere. That's because icons are an essential part of web design.

Here's where smart graphic designers go to find icons:

  • The Noun Project - The grand daddy. Enormous database of over 25,000 icons and growing daily. Each icon has a similar format so they always look professional and consistent.
  • Icons from The Noun Project
  • Icon Monstr - Free, simple icons discoverable through a search interface. Over 2,000 icons.
  • Icon Sweets - Love iOS7? This downloadable library has over 1,000 icons in the style of iOS7 (iOS7 is known for having outlined icons). Available for only $10.

Graphics & Logos

  • Creative Market - Amazing, handcrafted graphics from designers around the world. I always find top-rate stuff here.
  • Creative Market
  • 99 Designs - Crowdsource your logo: hold a contest and have 20 – 30 designers submit logo entries. Choose the one you like.
  • Scoop Shoot - Need photos from around town? ScoopShoot lets you hire people around town to take photos with their phones.
  • Subtle Patterns - Over 369, subtle (duh) patterns. They all work by being repeated, so they're perfect for websites.
  • Subtle Patterns
  • Colour Lovers - Have difficulty choosing which colours to use? Colour Lovers has literally millions of colour palettes created by users that are ready for you to use.

Two tools that will make you a design rockstar

  • Pixlr - Pixlr is like a free, online version of Photoshop.
  • Placeit - An incredible website. Just drag and drop screenshots and it will generate shots of your screenshot in realistic environments.

Placeit – Just upload a screenshot and Placeit will automatically place it in a new context

Bonus: Reader submitted resources

Savvy readers have mentioned additional tools that I hadn’t included. Here’s some that have stuck out to me:

  • Gimp – A bit of a learning curve, but a free tool for image editing (Thanks to Jesus Bejarano and Rekasays in the comments section).
  • Creative Commons images on Flickr – Thanks to 3stripe on Hacker News.

Friday, January 10, 2014

Sticky Table Headers & Columns

Sticky Table Headers & Columns

A tutorial on how to create sticky headers and columns for tables using jQuery. The solution is an alternative to other sticky table header approaches and it addresses the overflowing table problem including adding support for biaxial headers.

Sticky table headers are no longer a stranger to an average website user — unlike on paper when a reader's eyes can comfortably jump in saccades between top of a lengthy table and the rows of interest, the landscape orientation of most devices makes vertically-long tables hard to read. However, this very conundrum presents itself as a rich ground for UI experimentation that is not available to the printed media.

Sticky table headers, as their name implies, remains affixed to the top of the viewport even when the original table headers are scrolled out of view. They help to clarify the representation and purpose of data in columns when the visual reference to original table headers was lost. Besides that, the aid in orienting users in a sea of tabulated information, therefore avoiding the need to repeatedly and frustratingly, scroll between the top of the table where the header resides and the region of interest further down, typically lying out of the viewport.

There have been a handful of scripts and jQuery plugins written for the purpose of re-establishing the flow and ease of reading tables. While their implementation is flawless and efficient, they might not be an all-encompassing panacea for long tables. In some cases, tables have to obey certain layout rules that are not accounted for by the aforementioned plugins — such as tables that are forced to overflow due to dimension restrictions (e.g. to fit within a viewport).

While this tutorial does not try to serve as an all-encompassing panacea to the decidedly sticky problem with sticky table headers, it addresses more possible layout scenarios.

A Pure CSS-Based Solution with position: sticky?

Last September, a somewhat promising solution surfaced — a new possible value for the CSS position property is supported in the latest nightly build of WebKit or Chrome Canary. position: sticky sounded like a very promising new JS-free solution to the old and nuance problems of rigid table headers and beyond — its implementation can be also extremely useful in scenarios where a site navigation or a HTML5 app toolbar has to remain in view to the user at all times regardless of his/her scroll position along the document's y-axis.

Moreover, the sticky property value is supported in barely 6% of all global visits, making it a poor candidate for choice of implementation. Although it will not break layouts as browsers are dictated by W3C directive to ignore properties values that are unrecognized, invalid or illegal, it is not an ideal candidate when cross-browser functionality is desired.

The jQuery Based Solution

The jQuery-based solution is rather straight-forward. Before we move on with the JS itself, we should come to a common consensus how a semantically valid table should look like in the markup:

            <!-- more columns are possible -->
            <!-- more columns are possible -->
        <!-- more rows are possible -->
    <tfoot><!-- optional -->

What do we want to achieve?

We should enumerate the expectations of this script. It would be great if the script can accommodate various table layouts and situations:

  • Basic usage: Sticky table header only
  • Biaxial table headers
  • Wide tables:
    • Horizontal overflow: If there is a row header, we should introduce a sticky table column, too
    • Vertical overflow: Covered in basic usage
    • Biaxial overflow: Introduce sticky table header and column

Some CSS groundwork

Despite choosing to work with a JS-based solution, we will still have to rely on CSS for the basic styling of the headers. The important things is that we have to position the sticky header absolutely within a common parent with its full-fledge, original table sibling. The CSS is rather straight forward:

.sticky-wrap {
    overflow-x: auto;
    position: relative;
    margin-bottom: 1.5em;
    width: 100%;
.sticky-wrap .sticky-thead,
.sticky-wrap .sticky-col,
.sticky-wrap .sticky-intersect {
    opacity: 0;
    position: absolute;
    top: 0;
    left: 0;
    transition: all .125s ease-in-out;
    z-index: 50;
    width: auto; /* Prevent table from stretching to full size */
    .sticky-wrap .sticky-thead {
        box-shadow: 0 0.25em 0.1em -0.1em rgba(0,0,0,.125);
        z-index: 100;
        width: 100%; /* Force stretch */
    .sticky-wrap .sticky-intersect {
        opacity: 1;
        z-index: 150;
    .sticky-wrap .sticky-intersect th {
        background-color: #666;
        color: #eee;
.sticky-wrap td,
.sticky-wrap th {
    box-sizing: border-box;

Note: It is extremely important that you port the styles for your <table> elements over to .sticky-wrap. Although margins of pixel values can be easily calculated and applied to the new wrapper element, automatic margins are difficult to deal with (it is not possible to fetch the value of auto with jQuery in a straightforward manner) and it is easier if we simply apply the margins and width of tables to the wrapper element itself.

Let's say you have the following styles for your table:

table {
    margin: 0 auto 1.5em;
    width: 75%;

You can simply add the lines to ".sticky-wrap", too:

.sticky-wrap {
    overflow-x: auto; /* Allows wide tables to overflow its containing parent */
    position: relative;
    margin: 0 auto 1.5em;
    width: 75%;

I shall walk you through the steps that will, with a dozens of lines of JavaScript, create functional sticky table headers. For the ease of presentation, the script is presented in a logical flow towards problem solving — declaration of variables with the var statement can definitely be concatenated for a more compact and compressed script, but at the sake of logical flow and readability, therefore I have chosen not to adopt the latter approach.

We shall execute our function for every single instance of table selected for upon DOM ready. Moreover, we will also want to check if the selected tables contain the <thead> element and that the <thead> element is not empty and contains at least one <th> child. If the aforementioned criteria are not satisfied, our function will simply skip that instance of <table> and move on to the next.

$(function () {
    // Here we select for <table> elements universally,
    // but you can definitely fine tune your selector
    $('table').each(function () {
        if($(this).find('thead').length > 0 && $(this).find('th').length > 0) {
            // Rest of our script goes here

Step 1: Clone the <thead> element

Before we start, we will want to close the table head and declare some shorthand variables for ease of use:

// Declare variables and shorthands
    var $t     = $(this),
        $w     = $(window),
        $thead = $(this).find('thead').clone(),
        $col   = $(this).find('thead, tbody').clone();

Step 2: Wrap table and append new tables

In order to extend compatibility towards tables that have excessive width along the x-axis (e.g. having too many columns, or columns that are necessarily yet excessively wide), we wrap the table elements in a <div> element that is allowed to overflow along the x-axis. The width and margin properties are reset for the table so as to allow proper display within the wrapper.

// Wrap table
    margin: 0,
    width: '100%';
.wrap('<div class="sticky-wrap" />');

// Check if table is set to overflow in the y-axis
if($t.hasClass('overflow-y')) $t.removeClass('overflow-y').parent().addClass('overflow-y');

// Create new sticky table head (basic)
$t.after('<table class="sticky-head" />')

// If <tbody> contains <th>, then we create sticky column and intersect (advanced)
if($t.find('tbody th').length > 0) {
    $t.after('<table class="sticky-col" /><table class="sticky-intersect" />');
// Create shorthand for things
var $stickyHead  = $(this).siblings('.sticky-thead'),
    $stickyCol   = $(this).siblings('.sticky-col'),
    $stickyInsct = $(this).siblings('.sticky-intersect'),
    $stickyWrap  = $(this).parent('.sticky-wrap');

Step 3: Inserting cloned table contents

The trick now is to insert contents cloned from our original table into the newly created tables that will serve as our sticky elements:

  1. Sticky header will receive all contents from the cloned <thead> element
  2. Sticky column will receive contents from the first <th> from <thead> and all the subsequent <th> from <tbody>. This is assuming that each row only contains one table header cell.
  3. Sticky intersect will receive content from the top left most cell in the table

// Sticky header gets all content from <thead>

// Sticky column gets content from the first <th> of both <thead> and <tbody>
    .find('thead th:gt(0)').remove()
    .find('tbody td').remove();

// Sticky intersect gets content from the first <th> in <thead>
$stickyInsct.html('<thead><tr><th>'+$t.find('thead th:first-child').html()+'</th></tr></thead>');

Step 4: Functions

Here comes the most important part of our jQuery script — we decide what functions are needed for sticky headers to work and we declare them with the var statement to allow for easy callback. Two functions immediately come to mind:

  1. A function to determine the widths of individual <th> elements in the cloned header. Since we only cloned the <thead> element, the computed width of the cloned header will not be the same as the actual header itself, since the content of <tbody> itself, which may or may not influence the final width of each individual columns, is not included.
  2. A function to position the sticky header, so that we can update the vertical offset of the cloned header that is absolutely positioned when the scroll event is fired.
  3. A function to position the sticky column, so that we can update the horizontal offset when the parent element is overflowing.
  4. A function to calculate allowance — this feature is explained later in greater detail.

You may ask, why do I have to calculate the vertical offset of the header instead of simply using position: fixed? I, too, have contemplated over this issue, but it came to my realization that if we are allowing the table to overflow along the x-axis, the fixed positioning option has to go out of the window, because it will not scroll with the table in the event of a horizontal overflow.

// Function 1: setWidths()
// Purpose: To set width of individually cloned element
var setWidths = function () {
        .find('thead th').each(function (i) {
        .find('tr').each(function (i) {

        // Set width of sticky table head

        // Set width of sticky table col
        $stickyCol.find('th').add($stickyInsct.find('th')).width($t.find('thead th').width())

// Function 2: repositionStickyHead()
// Purpose: To position the cloned sticky header (always present) appropriately
    repositionStickyHead = function () {
        // Return value of calculated allowance
        var allowance = calcAllowance();

        // Check if wrapper parent is overflowing along the y-axis
        if($t.height() > $stickyWrap.height()) {
            // If it is overflowing
            // Position sticky header based on wrapper's scrollTop()
            if($stickyWrap.scrollTop() > 0) {
                // When top of wrapping parent is out of view
                    opacity: 1,
                    top: $stickyWrap.scrollTop()
            } else {
                // When top of wrapping parent is in view
                    opacity: 0,
                    top: 0
        } else {
            // If it is not overflowing (basic layout)
            // Position sticky header based on viewport scrollTop()
            if($w.scrollTop() > $t.offset().top && $w.scrollTop() < $t.offset().top + $t.outerHeight() - allowance) {                 // When top of viewport is within the table, and we set an allowance later
                // Action: Show sticky header and intersect, and set top to the right value
                    opacity: 1,
                   top: $w.scrollTop() - $t.offset().top
             } else {
                 // When top of viewport is above or below table
                 // Action: Hide sticky header and intersect
                     opacity: 0,
                     top: 0
// Function 3: repositionStickyCol()
// Purpose: To position the cloned sticky column (if present) appropriately
    repositionStickyCol = function () {
        if($stickyWrap.scrollLeft() > 0) {
            // When left of wrapping parent is out of view
            // Show sticky column and intersect
                opacity: 1,
                left: $stickyWrap.scrollLeft()
        } else {
            // When left of wrapping parent is in view
            // Hide sticky column but not the intersect
            // Reset left position
            .css({ opacity: 0 })
            .add($stickyInsct).css({ left: 0 });
// Function 4: calcAllowance()
// Purpose: Return value of calculated allowance
     calcAllowance = function () {
         var a = 0;

         // Get sum of height of last three rows
         $t.find('tbody tr:lt(3)').each(function () {
             a += $(this).height();

         // Set fail safe limit (last three row might be too tall)
         // Set arbitrary limit at 0.25 of viewport height, or you can use an arbitrary pixel value
         if(a > $w.height()*0.25) {
            a = $w.height()*0.25;

        // Add height of sticky header itself
        a += $sticky.height();

        return a;

Now, you may ask, what is allowance? What do we need it for? The basis of the allowance is simple — we do not want the sticky table header to follow us all the way to the end of the table, do we? It is unnecessary and run the risk of obfuscating the last table row. While this feature is optional (thus allowance is set to 0, see above), I highly recommend allowing at least one table row of height remaining. The height can be computed from the table itself, or you can set a fixed height.

As far as my experience go, I realize that I do not need the header much after the last three rows of the table is shown — that is because by then our eyes would have probably moved away from the table into the content below. This threshold is arbitrary and it is up to you to decide.

// Calculate allowance
// We allow the last three rows to be shown without the need for the sticky header to remain visible
$t.find('tbody tr:lt(4)').each(function () {
    allowance += $(this).height();

Step 5: Fire away, fire away!

Now we are done declaring all the functions we need for the correct styling and positioning of the sticky header. All is left is to bind event handlers to the $(window) object (previously abbreviated as $w for your convenience) and trigger the right function. Here is the game plan:

  1. When the DOM is ready, perform initial round of width calculations
  2. When all resources are loaded, perform second round of width calculations. This is important especially when your table contains resources that are loaded after DOM ready event, such as images, @font-face and more, which will influence how table column widths are computed.
  3. When the parent wrapper is scrolled, but this only happens if the content is overflowing. In the event of a scrolling event is detected, we want to reposition the sticky column
  4. When the viewport is resized, we want to recompute widths and reposition the sticky header
  5. When the window is scrolled, we want to reposition the sticky header

This can be easily summarized with the code below. Do note that the resize and scroll events are debounced and throttled respectively using Bel Alman's jQuery throttle+debounce plugin.

// #1: When DOM is ready (remember, we have wrapped this entire script in $(function(){...});

// #2: Listen to scrolling event on the parent wrapper (will fire if there is an overflow)
$t.parent('.sticky-wrap').scroll($.throttle(250, function() {

// Now we bind events to the $(window) object
// #3: When all resources are loaded
// #4: When viewport is resized
// (we debounce this so successive resize event is coalesced into one event)
.resize($.throttle(250, function () {
// #5: When the window is scrolled
// (we throttled this so scroll event is not fired too often)
.scroll($.throttle(250, repositionStickyHead);

And voila, you're done!


No tutorial is complete without a discussion — be it addressing potential drawbacks on the technicalities of implementation, or the explanation of my strategy in contrary to common expectations.

Why don't you use position: fixed?

Fixed positioning is a very tantalizing alternative, mainly because of the two advantages it confers:

  1. No calculations are needed for the sticky table header's vertical offset, because fixed position will cause the element to be positioned absolutely within the viewport and out of the document flow.
  2. Avoids the stuttering effect of the sticky table header playing catch up, as the scroll event is throttled and therefore the calculations are performed at fixed time intervals and not on the fly. It may appear less responsive to user movement and therefore less natural.

However, the issue with fixed positioning is that we are effectively removing the element from the document flow. In the event when the table width exceeds that of its containing and a horizontal overflow is absolutely necessary, the fixed position header will not scroll with the table because it is detached from the document layout. This is one of the major drawbacks with many jQuery plugins out there that offers sticky table header functionality and this tutorial was written partially to address this issue.

Why don't you use position: sticky?

The new position attribute, position: sticky, is only available to the latest version of WebKit browsers and require vendor prefixes. It is not supported in Firefox, Internet Explorer and Opera, therefore risking alienating a huge user base (~95%) due to lack of support. It is not official and standardized as of yet, so I would rather err on the side of caution and choose a more cumbersome but cross-browser friendly JS-based solution.

View Demo

Thursday, January 09, 2014

CSS Blend Modes could be the next big thing in Web Design

CSS Blend Modes could be the next big thing in Web Design
Cool-looking things that are difficult or downright impossible to replicate in CSS right now. Top row: Doublenaut, Graham Hicks, Jonathan Quintin and Geoff Teehan. Bottom row: Ben Johnson, Claire Morales, Alan Defibaugh and Jess Barlow

For everyone who has ever opened Photoshop or Illustrator you are most likely familiar with blend modes. Multiply, screen, overlay and soft light, to name a few can turn boring opaque layers into beautiful pieces of stained glass. However, what awesome "blend modes" do web designers have at their disposal for making websites beautiful? Opacity. Yep, that's it.

Blend modes and the web

It's a shame that we couldn't have had more blend modes to work with when the opacity property gained widespread support across browsers, but it turns out that ensuring Photoshop-like blend modes render uniformly across different browsers and implementations is no easy task. Some blend modes have been available in SVG through filters, but these are limited and don't see much use in the real world.

Despite this, things are changing fast and there is a draft specification titled CSS Compositing and Blending. Blend modes in CSS are being promoted heavily by Adobe Web Platform team (along with other interesting features like CSS regions and shaders).

Right now, the specification brings three brand new properties to CSS, background-blend-mode, mix-blend-mode and isolation. Let's explore!

Canvas 2D: Will it blend?

CSS Blend Modes could be the next big thing in Web Design - Canvas
Particles by Justin Windle.
Blend modes make this awesome demo really pop

First, here's a little secret, blend modes are now available for use with HTML5 Canvas in all the latest browsers except Internet Explorer. They are even supported on mobile Safari and Chrome. However, why should we stop there? Blend modes would be incredibly useful in CSS.

Blending in CSS: Say hello to background-blend-mode

CSS Blend Modes could be the next big thing in Web Design
Sixteen blend modes are coming to CSS. Demo.

The new background-blend-mode property allows you to specify blending between background layers of an element. Whether it be between an element's background-color and background-image, or a background-image CSS gradient, background-blend-mode mixes all the backgrounds together with the blend mode(s) you specify.

CSS Blend Modes could be the next big thing in Web Design
Medium even uses blend modes in their articles. Too bad our friend CSS isn't there to make this process a lot faster and easier.

Don't think this property would get much use? Don't go further than the website you're on right now. When uploading full-page backgrounds to an article, Medium gives you the option to apply a color to the background to make the title stand out a bit more. However, because browsers don't have blend modes in CSS, Medium has to do this the slow and costly way. They make six copies of the image you upload with different colors applied to each one, a process done on the server side. For the reader, this method is a lot slower than it could be with background-blend-mode. This new property could also be utilized elsewhere:

CSS Blend Modes could be the next big thing in Web Design - The Verge
The Verge's website is unique partly because of the pseudo blend modes they apply on their headlines. background-blend-mode could likely be used to make these kind of effects even better.

The super duper mix-blend-mode property

While background-blend-mode is strictly for blending backgrounds, we'd ideally also like to blend HTML and SVG elements like layers on a .psd. Fortunately, that is where the mix-blend-mode property comes in.

mix-blend-mode will blend elements with their backdrop. Perhaps you could experiment with a header that utilizes the screen blend mode rather than a simple background color with rgba(). There are also probably an infinite number of possibilities with loading animations and blend modes. The isolation property stops elements with mix-blend-mode from blending with the backdrop.

Implementation of the mix-blend-mode property is more complex than background-blend-mode so it is taking a bit more time, but don't let that get you down. Blend modes will be here soon!

Can I use blend modes now?

Not yet, but I would expect in 2014 you could be able to start. The specification has already been approved by the SVG working group and it needs approval from the CSS working group also to become a Candidate Recommendation. Once this happens soon, you can expect browsers to start shipping blend modes to browsers.

As for implementation, here's a brief summary: (Early January 2014)

  • Firefox: Implements background-blend-mode in version 29 but with bugs (see this demo) which they are working on. The mix-blend-mode property can be enabled in about:config.
  • Safari: Implements background-blend-mode in Webkit Nightly. Not mix-blend-mode.
  • Chrome and Opera: mix-blend-mode and background-blend-mode can be enabled in chrome://flags or opera://flags under "Experimental Web Platform Features".
  • Internet Explorer: Doesn't even support blend modes in Canvas. Can't find any info on current development of CSS blend modes.

Learn more

Thursday, January 09, 2014

WordPress Tutorial: What’s New in WordPress 3.8

What’s New in WordPress 3.8

WordPress 3.8 is here and there are a lot of exciting changes. Get up to date with the new features and start enhancing your blog or website today. In this video, author Morten Rand-Hendriksen reveals the redesigned dashboard, which is high contrast, clean and more customizable than ever and the new Twenty Fourteen theme, which provides a (highly requested) featured content area on your front page. The new dashboard is also fully responsive, so you can now visit the dashboard from your mobile device. This is great for making changes on the go!

Magazine Theme

The magazine theme is a page layout for WordPress (a "theme") that mimics the layout of a newspaper or magazine, with multiple boxes and spaces for photographs, allowing for certain posts to be called out.

Look and feel

In software design, look and feel is a term used in respect of a graphical user interface and comprises aspects of its design, including elements such as colors, shapes, layout and typefaces (the "look"), as well as the behavior of dynamic elements such as buttons, boxes and menus (the "feel"). The term can also refer to aspects of an API, mostly to parts of an API that are not related to its functional properties. The term is used in reference to both software and websites.

Look and feel applies to other products. In documentation, for example, it refers to the graphical layout (document size, color, font, etc.) and the writing style. In the context of equipment, it refers to consistency in controls and displays across a product line.

Look and feel in operating system user interfaces serves two general purposes. First, it provides branding, helping to identify a set of products from one company. Second, it increases ease of use, since users will become familiar with how one product functions (looks, reads, etc.) and can translate their experience to other products with the same look and feel.

Some Popular WordPress Magazine Themes From ThemeForest

Thursday, January 09, 2014

5 Frontend Frameworks and Libraries You Should Know

5 Frontend Frameworks and Libraries You Should Know

Most of us have heard about awesome front-end frameworks like Bootstrap and Foundation and well as many libraries that help the rapid prototyping and/or development of a web site or a web app.

Thursday, January 09, 2014

jQuery and CSS3 Magnifying Glass for Images

jQuery and CSS3 Magnifying Glass for Images
Have you ever want to add a super cool effect to your site of product images and couldn't find a perfect match? I bet these magnifying glass effect should fits in any layout.

These magnifying glass is created using CSS3 box-shadow and border-radius properties. jQuery is used to position it at the cursor coordinates and change the background-position accordingly. Moving the cursor away from the image gently fades out the magnifying glass bringing the image back to the default state. The idea of this post is generated from the walkthrough of Thecodeplayer.

View Demo

<img class="magniflier" src="image.jpg" width="160"/>

Having the class magniflier is important, as it is what our Javascript code is going to check for and we have set a value of 160 to scale down the image size before the hovering.

.glass {
  width: 170px;
  height: 170px;
  position: absolute;
  border-radius: 50%;
  cursor: crosshair;
  /* Multiple box shadows to achieve the glass effect */
    0 0 0 7px rgba(255, 255, 255, 0.85),
    0 0 7px 7px rgba(0, 0, 0, 0.25), 
    inset 0 0 40px 2px rgba(0, 0, 0, 0.25);
    display: none;

The glass effect is simply achieved with basic CSS3 shadows and rounded corners and we have set the display to none so as to keep the glass invisible until it's hovered-on.

$(function() {

  var native_width = 0;
  var native_height = 0;
  var mouse = {x: 0, y: 0};
  var magnify;
  var cur_img;

  var ui = {
    magniflier: $('.magniflier')

  // Connecting to the magnifying glass
  if (ui.magniflier.length) {
    var div = document.createElement('div');
    div.setAttribute('class', 'glass'); = $(div);


  // All the magnifying will happen on "mousemove"

  var mouseMove = function(e) {
    var $el = $(this);

    // Container offset relative to document
    var magnify_offset = cur_img.offset();

    // Mouse position relative to container
    // pageX/pageY - container's offsetLeft/offetTop
    mouse.x = e.pageX - magnify_offset.left;
    mouse.y = e.pageY -;
    // The Magnifying glass should only show up when the mouse is inside
    // It is important to note that attaching mouseout and then hiding
    // the glass wont work cuz mouse will never be out due to the glass
    // being inside the parent and having a higher z-index (positioned above)
    if (
      mouse.x < cur_img.width() &&
      mouse.y < cur_img.height() &&
      mouse.x > 0 &&
      mouse.y > 0
      ) {

    else {;


  var magnify = function(e) {

    // The background position of will be
    // changed according to the position
    // of the mouse over the img.magniflier
    // So we will get the ratio of the pixel
    // under the mouse with respect
    // to the image and use that to position the
    // large image inside the magnifying glass

    var rx = Math.round(mouse.x/cur_img.width()*native_width -*-1;
    var ry = Math.round(mouse.y/cur_img.height()*native_height -*-1;
    var bg_pos = rx + "px " + ry + "px";
    // Calculate pos for magnifying glass
    // Easy Logic: Deduct half of width/height
    // from mouse pos.

    // var glass_left = mouse.x - / 2;
    // var glass_top  = mouse.y - / 2;
    var glass_left = e.pageX - / 2;
    var glass_top  = e.pageY - / 2;
    //console.log(glass_left, glass_top, bg_pos)
    // Now, if you hover on the image, you should
    // see the magnifying glass in action{
      left: glass_left,
      top: glass_top,
      backgroundPosition: bg_pos


  $('.magniflier').on('mousemove', function() {;
    cur_img = $(this);

    var large_img_loaded ='large-img-loaded');
    var src ='large') || cur_img.attr('src');

    // Set large-img-loaded to true
    //'large-img-loaded', true)

    if (src) {{
        'background-image': 'url(' + src + ')',
        'background-repeat': 'no-repeat'

    // When the user hovers on the image, the script will first calculate
    // the native dimensions if they don't exist. Only after the native dimensions
    // are available, the script will show the zoomed version.
    //if(!native_width && !native_height) {

      if (!'native_width')) {
        // This will create a new image object with the same image as that in .small
        // We cannot directly get the dimensions from .small because of the
        // width specified to 200px in the html. To get the actual dimensions we have
        // created this image object.
        var image_object = new Image();

        image_object.onload = function() {
          // This code is wrapped in the .load function which is important.
          // width and height of the object would return 0 if accessed before
          // the image gets loaded.
          native_width = image_object.width;
          native_height = image_object.height;

'native_width', native_width);
'native_height', native_height);

          //console.log(native_width, native_height);

          mouseMove.apply(this, arguments);

'mousemove', mouseMove);

        image_object.src = src;
      } else {

        native_width ='native_width');
        native_height ='native_height');
    //console.log(native_width, native_height);

    mouseMove.apply(this, arguments);'mousemove', mouseMove);
  });'mouseout', function() {'mousemove', mouseMove);



Read through every attribution for better understanding of what operation each line performed.

  • Use the class magniflier to enable the effect on any image.
  • Attach data-large="image.jpg" to the HTML markup if you want to use different image for the zoomed version.

Now you have a simple-to-use magnifying glass plugin for your next project.

Thursday, January 09, 2014

45 Useful JavaScript Tips, Tricks and Best Practices

45 Useful JavaScript Tips, Tricks and Best Practices
As you know, JavaScript is the number one programming language in the world, the language of the web, of mobile hybrid apps (like PhoneGap or Appcelerator), of the server side (like NodeJS or Wakanda) and has many other implementations. It's also the starting point for many new developers to the world of programming, as it can be used to display a simple alert in the web browser but also to control a robot (using nodebot, or nodruino). The developers who master JavaScript and write organized and performant code have become the most sought after in the job market.

Tuesday, January 07, 2014

50 Free Graffiti Fonts for Designers

Free Graffiti Fonts - Inner City

In recent decades, graffiti has moved from an urban nuisance to a professional business - thanks to the work of some incredible street artists. And with the art form ever growing in popularity, there are now tons of graffiti font styles available online for creatives use in urban artwork.

Monday, January 06, 2014

What is the DOM?

What is the DOM?

But the HTML you write is parsed by the browser and turned into the DOM.

Monday, January 06, 2014

5 .htaccess Snippets to Borrow from HTML5 Boilerplate

htaccess Snippets
HTML5 Boilerplate is an awesome website template when you want all best pieces in place for you when you start your project. A while back I covered 7 CSS Snippets to Borrow from HTML5 Boilerplate, so today I want to feature a few .htaccess settings which could speed up, secure and make your site very much more useful!