Why I use LESS Part 1

Posted by & filed under CSS.

A few months back I was looking at some of the great work being done with responsive designs. Specifically Andy Clarke’s 320 and Up ,the Bones theme for WordPress and Twitter’s Bootstrap. All of those projects had recently switched over to using pre-processors such as LESS and SASS. I wasn’t too keen on getting into pre-processors thinking they were a pain to install and use. After looking at the LESS homepage and seeing things like variables and simple easy to use functions, I was sold on the idea. I bought a license for CodeKit and I’ve never looked back!

Now they both have a learning curve and I had a good look at both. In the end I chose to stick with LESS as the set-up is a no brainer and its simple enough for me to use! I don’t need a ton of fancy powerful functions that SASS provides.

In part 1 I’ll cover my two favourite things about using LESS: variables and color functions.

One thing I had been doing lately was to create classes for my theme colours and I would apply the additional classes as needed. With LESS you can create variables and then even use some of the colour functions to derive your colour palette.

So I used to write this:

.yellow {color: #f1f188;}
.l-grey {background: #f2f2f2;}

And with LESS:

@yellow: #f1f188;
@l-grey: #f2f2f2;

Then in the actual .less file I can simply write something like this:

#module {
    background: @l-grey;
    color: @yellow;
}

Now is that is big deal? Well yes it is! You see before I had to add the class in the HTML or I had to write in the colour code in each css block. With LESS I create my variables, use them in the .less file and the pre-processor will substitute them for me. That way I just write the colour code in one spot.

Now to derive your colour palette with a lighter and darker colour and to also add say a hover state variation.

@m-grey: darken(@l-grey, 10%); //darken by 10% light grey
@d-grey: darken(@m-grey, 10%); //darken by 10% mid grey

Now for a hover state colour you could use the fadeout which makes the colour *more* transparent

#menu-button:hover {
background: fadeout(@l-grey, 15%);
}

If nothing else, I’d suggest switching to LESS to take advantage of variables and the colour functions. Its a lot easier to just use a colour variable than to have to use classes.

In part 2 I’ll go over some of the other powerful features such as mixins and how to leverage the reusable code to make your CSS consistent and a lot simpler when handling CSS3 features like box-shadow and rounded corners while keeping up with all the browser’s vendor prefixes.

DLP Main Site Update

Posted by & filed under Portfolio.

So my wife’s main showcase website needed an update as I have been wanting to make a few changes. Some of the items that needed to be updated included:

  • Upgrade the jQuery to the latest version (1.7.2)
  • Unoslider plugin, the responsive touch enabled slider being used.
  • Replace old sprite based icons with vector based font icons from IcoMoon.

The old files were brought into Coda 2 and I also converted my large CSS development file into several pieces of LESS files and imported the whole project in CodeKit. First of all I’ve got to say that I’m in love with that combination: Coda 2 and CodeKit! Once you set up your project in both including all the FTP information it really speeds things out and CodeKit takes care of minifying it all for you.

One little annoyance I had was that once you saved your main “style.less” file in Coda 2, Coda’s file transfer manager would pick up the fact that the .less file has been saved but it didn’t see the .css update? After searching for a while on google, I came across a simple solution:

  • Make sure CodeKit and Coda 2 are running.
  • Right-click on the style.css file within Coda 2 and “open with” CodeKit.
  • You’ll get and error message in CodeKit, simply ignore it.
  • You will now automatically have your minified .css added to the list of updated files to be uploaded.
  • In Coda 2, the shortcut to upload all files in the queue is : contorl + command + p

With that set-up and all the different website components split up, I was left with a very small and manageable style.less file. LESS and CodeKit take care of all the hard work!

The updates to the site aren’t major content-wise, but the little subtleties such as super crisp vector font icons and updated UnoSlider are a nice touch!

The results of my hard labour can be found on her “main site”.

Mobile home page for DLPhotography

Posted by & filed under Portfolio.

Well I’ve been keeping an eye out on my wife’s website traffic on Google Analytics and as expected I have been noticing quite the increase in mobile traffic. Its currently at around 35% mostly iPhone/iPad with a mix of  Android and BlackBerry devices.

The landing page is actually part of the WordPress install and I was never really happy with it, but it was working. Her WordPress blog is based on Twenty Eleven and I had been contemplating having a look at redoing her blog and base it on a mobile first template such as the excellent Bones Responsive which is based on the 320 and Up principal. I’ll get to that sometime in the fall when I’ve got more spare time. For now I just want to get her a mobile friendly landing page.

A while back I had bought the excellent font based icons from Keyamoon called IcoMoon, seriously if you are still messing with sprites do yourself a favour and switch to font icons. I had previously made a sprite for the social icons before the big Pinterest craze so I hadn’t included one for it. Thankfully Keyamoon promptly added one to his collection so I used his awesome web app and created a custom social icon subset which once exported weighs in at between 2 to 6 kb in size. (exports to 4 formats including ttf and svg)

My wife had previously requested 3 primary options on the landing page: main site, blog and Facebook. Now again, having looked at the analytics, Facebook is a significant referrer. So it doesn’t make sense taking visitors right back to the site that likely just referred them to her site. Instead we cut down the options to: main site and blog and the Facebook link back will be taken care of by one of the icons.

The approach I took was to start at 100% width and to set a breakpoint where I would add more assets to visitors likely on a speedier connection. I chose to set that breakpoint at around 700px. I set that breakpoint using em instead of px in the end as users could be zooming (pinch in/out on iPhone) and it would mess with the breakpoint’s effectiveness. So to convert that to ems, simply use the basis that 1em = 16px. So 700px / 16px = 43.75em. I like nice round numbers so I picked 45em which equals 720px.

Up to 720px the two main navigation links will simply be rounded buttons. Once you pass the 720px breakpoint, they convert to nice images with the text below. To accomplish this I used background images which start off set to nothing and then at 720px switch in the nice images.

Below the two primary navigation links I place the font based social icons. These are there starting right from the beginning and they scale up perfectly.

iphone preview

iPhone preview

 

iPad preview

iPad preview

 

TAO Program WordPress Child Theme

Posted by & filed under Portfolio.

I wanted to help out our son’s Taekwon Do teacher’s new initiative called TAO Program. He is trying to raise funds to subsidize Taekwon Do classes for children and families who normally couldn’t afford the full cost.

I wanted to set him up on an easy to use Content Management System (CMS), so I turned to WordPress. I created a simple child theme of the default “Twenty Eleven” theme and added a custom home.php file. He wanted a two column news and events on the home page and those would be the only two categories he’d use.

In the custom home.php I created a percentage based two column layout to split up the page in half, floated left and separated with padding.

.l-fullwidth {
width: 100%;
}

.l-constrained {
width: 93%;
margin: 0 auto;
}

.l-halfwidth {
width: 46%;
float: left;
padding-right: 8%;
}

.l-halfwidth.last {
padding-right: 0;
}

—————————–

Now for the “home.php” part:

<div class="l-fullwidth">
<div class="l-constrained" role="main">
<?php if ( have_posts() ) : ?>
<div class="l-halfwidth news">
<h2>NEWS</h2>
<?php $temp_query = $wp_query; ?>
<?php query_posts('category_name=news&showposts=5'); ?>

<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
</div>
<?php endwhile; ?>
</div>
<div class="l-halfwidth last events">
<h2>EVENTS</h2>
<?php $temp_query = $wp_query; ?>
<?php query_posts('category_name=events&showposts=5'); ?>

<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
</div>
<?php endwhile; ?>

</div>

This code is inserted between the get_header and get_footer calls. (just before the 404 code)

For the slideshow I used Flexslider and added the script into the WordPress output using this:

<?php
function my_scripts_method() {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js');
wp_enqueue_script( 'jquery' );
wp_register_script( 'plugin', get_stylesheet_directory_uri() . '/js/plugin.js' );
wp_enqueue_script( 'plugin' );
wp_register_script( 'script', get_stylesheet_directory_uri() . '/js/script.js' );
wp_enqueue_script( 'script' );
}

add_action('wp_enqueue_scripts', 'my_scripts_method');
?>

**The Flexslider plugin is included in the plugin.js file**

 

Danielle Lynn Photography Feb 2012 Remake

Posted by & filed under Portfolio.

With the little bit of spare time I have, my lovely bride has had me working away on a new redesign/remake of her photography website and blog.

I had a few things I wanted to achieve with this redesign:

  1. No Flash for the image galleries
  2. Designed for desktop and responsive down to tablets (600px min width)
  3. Optimized images/css/js

I started off with getting my hands on the latest “HTML5 Boilerplate” and started building the site from there. Now I had two sites to worry about, the “main” showcase site, straight forward html and then the WordPress blog which I wanted to transition from the current child theme based on Thematic over to a child theme based on Automattic’s TwentyEleven theme. Why? well TwentyEleven is responsive and its a pretty clean starting point.

No flash was going to be an easy thing to achieve as there are lots of fantastic jquery plugins out there. Previously, I had been playing with “Flexslider” which I have found to be very easy to set-up and it performed beautifully. In the end, I stumbled on “Unoslider” at Codecanyon.net. I usually try to stick to the free alternatives, but in this case I decided to part with $9 in favour of the option to get support if needed. Plus, the unoslider’s default styling matched Danielle’s colour theme perfectly.

The responsive design for the main html site was done by hand as the content is fairly limited so a need for css frameworks was not necessary. Based on techniques I picked up while reading the fantastic “Responsive Web Design” I created the responsive site.

For both the blog and main website we used a web font, “Flamenco” from Google’s webfonts library. It was giving me aliasing problems on IE 8 and the latest Chrome and Firefox on Windows XP and Win 7. (IE9 was fine) I used FontSquirrel’s converter and built a full @font-face stack and it help smooth out the fonts by quite a margin.

My last step was to optimize everything as much as possible. For static content I was initially using Rackspace’s awesome Cloudfiles but both YSlow and Chrome’s Audit tool were complaining of short expiry dates. I was also seeing significant delays loading assets. So I fired up Terminal on my Mac Book and started tracing the server from Rackspace (Akamai) which kept consistently giving me a NE USA server with an average of 40-50 ms latency.

I run my site(s) using a shared hosting plan with Hostpapa.ca so I decided to set-up 2 static content delivery subdomains. I then used part of the HTML5 BP .htaccess file with the expiry rules and placed a copy at the root of each CDN subdomain. Once everything was switched over to the new CDN serving from Toronto, it was blazing fast, 8-15 ms latency, very fast at loading images. In the end, this solution works for me as you intended clientele is Ottawa, Ontario and area, so all the advantages of Rackspace’s CloudFiles is of not much use as US or overseas visitors will likely not be paying clients. (they can wait a bit and be served by the Toronto server!)

Anyway, without further adieu here is the final product which can be viewed by visiting Ottawa Photographer, Danielle Lynn Photography’s website:

New landing page for Ottawa Photographer Danielle Lynn Photography New main website for Ottawa Photographer Danielle Lynn Photography New blog site for Ottawa Photographer Danielle Lynn Photography

here we go!

Posted by & filed under news.

Alright, I found a few minutes tonight to work on the site. I came across this really cool and clean WordPress theme from darylkoop.com. Its a child theme for WordPress’ TwentyEleven theme. So…. its responsive and quite lean!

I really like it!