Category: CSS

Last post, I created my own cusomised Magento theme. It looks crap, but it works! Instructions here In this post, I am going to take my fancy bootstrap 3 store template, and integrate it in to our newly created theme. The first stage is learning how the templates all work, so we’ll bring in the js and css, and make our own header until we get the hang of it. Then we can take the HTML from our template and add it in. But first things first.


The theme I downloaded has Bootstrap 3, but not the latest version, so I’m grabbing the latest from

Once downloaded, copy the following files into your theme in /skin/frontend/fashion/default :


Stick your jquery.min.js in /js/lib/jquery.  There’s already a jQuery in there, but yours might be newer. You’ll notice a noconflict.js too. That stops jQuery and Prototype from conflicting with one another.
Ok, now we’ve done that, we need to configure our /app/design/frontend/fashion/default/layout/local.xml file. Javascript & Css go in our head block. So lets add it:

<?xml version="1.0" encoding="UTF-8"?>
 * local.xml
 * Local layout modifications for our local theme
 * @category    design
 * @package     fashion
 * @copyright   Copyright (c) 2015 delboy1978uk.
<layout version="0.1.0">
        <reference name="head">
            <action method="addJs"><script>js/lib/jquery.min.js</script></action>
            <action method="addJs"><script>js/lib/jquery/noconflict.js</script></action>
            <action method="addItem"><type>skin_js</type><name>js/bootstrap.min.js</name></action>
            <action method="addItem"><type>skin_css</type><name>css/bootstrap.min.css</name></action>
            <action method="addItem"><type>skin_css</type><name>css/styles.css</name></action>
            <action method="addItem"><type>skin_css</type><name>css/styles-ie.css</name></action>

As you know, the C of CSS stands for cascading. The styles.css in the base theme will be called first, which obviously is unwanted behaviour which could cause class conflicts, so we really want to stop the base theme from loading it. So add this line before the bootstrap.min.css line :

<!-- Remove base theme styles.css --> 
<action method="removeItem"><type>skin_css</type><name>css/styles.css</name></action>

Now let’s deal with the world’s shittiest, least standards compliant browser out there (if you can call it a browser) : Internet Explorer.  The usual suspects apply here, namely respond.min.js & . Download them into the theme js folder, and add them under that bootstrap js line (notice the params bit):

<action method="addItem"><type>skin_js</type><name>js/html5shiv.js</name><params/><if>lt IE 9</if></action>
<action method="addItem"><type>skin_js</type><name>js/respond.min.js</name><params/><if>lt IE 9</if></action>

You can also add a config section specifically for print, so here’s what to add after the reference=”head” section:

<print translate="label" module="page">
    <label>All Pages (Print Version)</label>
    <!-- Mage_Page -->
    <block type="page/html" name="root" output="toHtml" template="page/print.phtml">

        <!-- This block allows the print.phtml template to get the logo -->
        <block type="page/html_header" name="header" as="header"/>

        <block type="page/html_head" name="head" as="head">

            <action method="addCss"><stylesheet>css/styles.css</stylesheet></action>
            <action method="addItem"><type>skin_css</type><name>css/styles-ie.css</name><params/><if>lt IE 8</if></action>
            <action method="addCss"><stylesheet>css/widgets.css</stylesheet></action>
            <action method="addItem"><type>skin_css</type><name>css/print.css</name></action>

        <block type="core/text_list" name="content" as="content" translate="label">
            <label>Main Content Area</label>


Now we add our ‘root’ template file. At the top, in the default node but above the <reference name=”head”> node, add the following (for the example I’m using the 2 col layout):

<reference name="root">
      <action method="setTemplate">

Great! Now it’s time to rip apart the .phtml files we copied over from the base theme! Open /app/design/frontend/fashion/default/template/page/2columns-left.phtml

<!DOCTYPE html>
<html xmlns="" xml:lang="<?php echo $this->getLang() ?>" lang="<?= $this->getLang() ?>">

        <?= $this->getChildHtml('head') ?>

    <body<?= $this->getBodyClass() ? ' class="'.$this->getBodyClass().'"' : null; ?>>
        <?= $this->getChildHtml('after_body_start') ?>
        <?= $this->getChildHtml('global_notices'); ?>
            <?= $this->getChildHtml('header'); ?>
        <section id="after-header">
            <div class="container">
                <?= $this->getChildHtml('slider'); ?>
        <section id="maincontent">
            <div class="container">
                <div class="row">
                    <?= $this->getChildHtml('breadcrumbs'); ?>
                    <aside class="col-left sidebar col-md-3">
                        <?= $this->getChildHtml('left'); ?>
                    <div class="col-main col-md-9">
                        <?= $this->getChildHtml('global_messages'); ?>
                        <?= $this->getChildHtml('content'); ?>
        <footer id="footer">
            <div class="container">
                <?= $this->getChildHtml('footer'); ?>
        <?= $this->getChildHtml('before_body_end'); ?>
        <?= $this->getChildHtml('global_cookie_notice'); ?>
        <?= $this->getAbsoluteFooter(); ?>


Okay, do the same for the other template files too! You know the score! Ditch the Magento markup and replace with BS3 awesomeness!
Check out my next post where we’ll start editing the view files and creating blocks etc!


If you haven’t used sourcemaps, now is the time!

With the advent of compiled CSS like LESS or SASS, or minified/uglified JS, it makes debugging awkward as you cant see the original lines of code that you wrote. Cue CTRL_F’ing to find that line to tweak! But not any more!

When you generate your LESS/SASS, if you tell it to compile a sourcemap too, it will create one! This allows your browser to report which line of the less or scss file the rule in question came from.

For the Less compiler command, you have several options:

--source-map[=FILENAME]  Outputs a v3 sourcemap to the filename (or output
--source-map-rootpath=X  adds this path onto the sourcemap filename and less file paths
--source-map-basepath=X  Sets sourcemap base path, defaults to current working directory.
--source-map-less-inline puts the less files into the map instead of referencing them
--source-map-map-inline  puts the map (and any less files) into the output css file
--source-map-url=URL     the complete url and filename put in the less file

For Sass, you just add the option at the end of the command:

sass sass/screen.scss:stylesheets/screen.css --sourcemap

Now in Firefox, open your page, right click, and click Inspect Element (not the Firebug one, the default Firefox Inspector!)

In the CSS rules pane, right click, and make sure show original sources is checked.

Screen Shot 2015-05-18 at 16.57.27 (2)

To the right of the actual rule, you click the link which would usually take you to the CSS file for viewing, but now, it takes you to your Less/Sass file! You can now tweak rules and save them directly from the inspector!

Screen Shot 2015-05-18 at 17.01.11

In my new workplace, our SASS files are compiled by Gulp automatically. (In my last work I had lessc configured in PHPStorm). If your own files are automatically built, then you should also checkout Firefox addons for live reloading! The great thing about that is that the CSS files update without refreshing! Great if you have session info or other info that might need reinstantiating, you dont have to keep keying stuff in! Have fun!

Using Emmet in your IDE

Emmet is awesome! It’s a little tool (once called Zen Coding) that gives you loads of keyboard shortcuts for generating HTML and CSS markup! Give it a try! Install an Emmet plugin into your IDE. Then, in a view file, try typing this:


In PHPStorm, hit TAB after typing that. In Eclipse/Aptana, you press CTRL-E. Suddenly, it changes to:

<table id="applications" class="table-striped table-hover table">

As you can imagine, this saves a LOT of time! Check out the Emmet Cheatsheet here:

You can download the plugin for your IDE here:
Have fun!

I love LESS! However having to run lessc every time I edit my less file is LAME! Adding File watchers in PHPStorm means that when you save your file, it will automatically compile your CSS! We are also going to add Javascript and CSS minification, which helps increase page load speeds and also make it harder for nosey people to examine your javascript! Lets go!

First up, lets install node.js by visiting
Next, we install less and yuicompressor:

npm install -g less
 npm install -g yuicompressor

Also on Windows, everything cracks up unless you add a PATH environment variable for the modules. In Control Panel in System, click Advanced System Settings, click Environment Variables and add the node modules folder to the PATH variable, or add it if its not there:


Go to File > Settings, and under the project settings look for File Watchers. Click the green + to add a watcher. Select LESS.

All that is required is that you put the correct path into the program field. This may be slightly different depending on your setup. For windows users, the modules can usually be found in :


And on linux machines, you can find it elsewhere. I cant remember offhand, but just take note of the output while you are installing it and you wont go far wrong.

Now you can edit the head section of your website, replacing style.css with style.min.css, and the same also for your javascript! Awesome 🙂

CSS – Why Less is MORE

There’s absolutely NO point of me rewriting a perfectly good article thats already out there, but I will tell everyone:



It is absolutely incredible. I’m ditching all my current CSS files and refactoring them to use this stuff! There’s no turning back from this yeehah!


Here’s how to install the LESS Compiler and set up auto compiling of CSS in PHPStorm:

CSS overrides for iPhone & iPad

Website looking great? Did you check it on your phone? Or your iPad?

Sometimes buttons and things are bigger and ruins your layout etc. Whatever your issue is, you might not need a completely separate CSS file. You can override rules using this kind of thing:

/* iPad [portrait + landscape] */
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
 height: 36px;
 font-size: 16px;
/* iPhone [portrait + landscape] */
@media only screen and (max-device-width: 480px) {
 height: 36px;
 font-size: 16px;

Easy as that!

My shiny new website uses an awesome jquery tool called Coda Slider. It’s really good, but I kind of left the old fashioned people with a 1024×768 resolution behind, as my sites default width (and my slider image widths) are  1200px!

Anyway, I couldn’t have cared less, everyone uses a laptop or widescreen monitor anyway! Until that is the feedback started coming back. Looks like I need to fix this then :-s

First up, here’s the way the coda slider works:

<script src="/js/coda/jquery.coda-slider-3.0.min.js" type="text/javascript"></script>
 <link href="/js/coda/coda-slider.css" rel="stylesheet" /> the head, obviously. In your body, you set it out like this:

<div class="coda-slider-wrapper">
 <div class="coda-slider preload" id="coda-slider-1">
   <div class="panel">
     <div class="panel-wrapper">
       <img src="/img/coda/banner1.png" />
   <div class="panel imagepanel">
     <div class="panel-wrapper" style="text-align: center;">
       <img src="/img/coda/ddale.jpg" />
     <div class="panel-wrapper" style="text-align: center;">
       <img src="/img/coda/let-your-property.png" />
     <div class="panel-wrapper" style="text-align: center;">
       <img src="/img/coda/mobile.jpg" />

And in your <script> :

var slide = $('#coda-slider-1').codaSlider({
 autoHeight : false,
 autoSlide : true,
 dynamicArrows : false

Now we have an awesome slider!

However, the guys with the 1024x768px monitors are crying in pain! So we can hack a quick fix for them:

if (screenwidth <= 1024) 
    $('div.panel-wrapper img').css('width','1000');
    $('.coda-slider-wrapper .coda-slider').css('width','1000');
    $('.coda-slider-wrapper .coda-slider').css('height','291');
    $('.coda-slider-wrapper .coda-slider .panel').css('width','1000');

That shrinks the image width and panel containers to fit 🙂 A bit hacky, but I still like it. Next time though, I’ll do my CSS in em’s and %ages!