Compiling Twitter Bootstrap 2.0 with SimpLESS on Windows 7

Using LESS with Bootstrap

This afternoon, after a couple of hours of poking and prodding various pieces of software, I worked out how to compile Twitter Bootstrap 2.0 using SimpLESS. This is what I’ve discovered so far…

CSS frameworks

Having been an avid user of the Blueprint CSS framework for a number of years now (I created what has become quite a popular cheatsheet for the framework, which even got released with the Joomla! CMS a few versions back) I am aware of its limitations, particularly in the area of responsive web design.

So I’ve been keeping an eye on how various CSS frameworks have been developing, such as 320 and up, Less Framework 4 and Twitter Bootstrap.

Twitter Bootstrap reached version 2.0.0 in late January of this year; the current version is 2.0.3 (released 24 April 2012). I downloaded it last week and have spent a couple of days idly playing around with it. with a view to using it on a future web project.

One thing that I was uncertain about, however, was how to use the LESS files.

LESS

When it comes to CSS pre-processors, such as LESS and Sass, I’m a bit late to the party. What can I say, I’ve got twins and a 16 month old and I still don’t get enough sleep.

Sass claims that it “makes CSS fun again”; LESS that it “extends CSS with dynamic behavior such as variables, mixins, operations and functions.” Chris Coyier prefers SASS. Bootstrap from Twitter uses LESS so I guess, for now, I’m going with LESS.

I’ve dabbled with both LESS and Sass over the last year but not enough to get proficient in either, and certainly not enough to use either in a production environment. One put-off for me, certainly in the early days, was the lack of GUI to compile the files. Sass uses Ruby; LESS uses JavaScript (either client- or server-side).

These days, however, there are a number of standalone desktop applications that allow you to compile LESS code without needing to poke around with command-line commands. One of my favourites is SimpLESS from We Are Kiss.

SimpLESS

SimpLESS is available for Windows, Linux and Mac. It installs as a very simple application onto which you drag-and-drop your directory/folder containing the .less files, click a button and it convert your LESS files to CSS. It’s just a shame that you can’t batch process all the files, a feature that WinLess offers.

By default, if your directory structure includes a \less directory and a \css directory then SimpLESS will compile all your .less files into .css files within the \css directory. Sounds simple enough. No faffing, and you get a very usable CSS file at the end of it all.

Also by default SimpLESS will compress/minify your CSS files unless you include //simpless:!minify in the .less file. I include it at the top of the file.

Bootstrap from Twitter

Twitter Bootstrap 2.0 uses LESS. It has a directory full of LESS files that control every aspect of the framework: accordion, alerts, breadcrumbs, button-groups, buttons, carousel, forms, layouts, etc.

So, if you want 16 columns instead of 12 edit the @gridColumns, @gridColumnWidth and @gridGutterWidth variables within variables.less and recompile. That’s how customisable the framework is.

Except… when I did that I and I used SimpLESS to compile the LESS file I got an error:

Syntax error in progress-bars.less on line 33

Syntax error in progress-bars.less on line 33

Syntax error in progress-bars.less on line 33.

After a little digging around on the internet and I discovered a very helpful post on GitHub. This is what I did…

How to fix SimpLESS to compile Twitter BOOTSTRAP 2.0 on Windows 7

  1. Download and unzip Twitter Bootstrap v.2.0;
  2. Copy the \less directory to a new test directory and create a new \css directory as its sibling, so you will have:
    \test
    \test\less
    \test\css
  3. Download and install SimpLESS;
  4. Download the fixed version of less.js from We Are Kiss;
  5. Replace the existing less.js located at
    C:\Program Files\SimpLESS\Resources\js (32-bit Windows)
    C:\Program Files (x86)\SimpLESS\Resources\js. (64-bit Windows);
  6. Run SimpLESS;
  7. Drag your \test directory onto SimpLESS;
  8. Click the ‘reload’ icon against bootstrap.less to compile it;
  9. Success! You will now have compiled .css files in \test\css
Successfully compiled LESS file

Successfully compiled LESS file

A few things I noted:

  • If you run SimpLESS without the fixed less.js file then you will need to restart the application after you copy over the fixed less.js file in order for it to start using the new version.
  • less.js v.1.3.0 from the official LESS website does not work; only this fixed version from We Are Kiss works as expected.
  • The two main files to compile are bootstrap.less and responsive.less.

Time to get creating…

Blueprint cheat sheet updated for version 1.0.1

20110618-blueprintcheatsheet43

This week I updated my Blueprint CSS framework cheat sheet for Blueprint v.1.0.1 which was released last month.

Changes

I mostly fixed a few typos, and added the new features that the latest version of the framework added: mostly HTML5 input attributes. I made the following changes:

  • NEW—FORMS Added new HTML5 input attributes: email and url.
  • NEW—IE FIXES Added IE8#HACK.
  • FIX—FLOAT CLASSES p .left and p .right was showing the margins only for p .left.
  • FIX—Page 2 was showing a completely different version number from page 1.
  • CHANGE—Updated the list of URLs on page 2, removing one that is now redundant.

Download

You can download it from the usual places including garethjmsaunders.co.uk/blueprint/

It’s released under a Creative Commons Attribution-ShareAlike 2.5 UK license so feel free to use it, adapt it, whatever… The source document (in Microsoft Publisher 2010 format) is available on the site too.

Enjoy!

Extending colborder in Blueprint CSS

Blueprint

For the last few months, when time has allowed, I’ve been working on a new CSS framework combining my favourite elements from Blueprint CSS framework and 960 Grid System but this week I ran into a problem.

I’m developing the adapted framework to use when I redesign my website later this year. When it’s completed I will also make it publicly available on my website to whoever wants to use it and adapt it.

This is what I want

On Friday night, while testing it, I spotted something about the original Blueprint framework that I hadn’t noticed before.

It was to do with the colborder rule. What if I want to do this:

12 columns of text

That is create two blocks of text, the first spanning six columns with two blank columns appended on the end, then a colborder (which as the name suggests is a border that span an entire column) and finally the second block of text which spans three columns.

Just to be clear, in this example I’m using an adapted Blueprint grid. The default grid uses 24 columns, but in this example I’m using 12 columns as fewer and wider columns make it easier to demonstrate what I’m talking about.

The code, I initially thought, would look like this:

45
46
47
48
49
50
51
52
53
<div id="column1" class="span-6 append-2 colborder">
  <h2>span-6 append-2 colborder</h2>
  <p>Lorem ipsum dolor sit amet, ... </p>
</div>
 
<div id="column2" class="span-3 last">
  <h3>span-3 last</h3>
  <p>Lorem ipsum dolor sit amet, ... </p>
</div>

My blank columns have disappeared

But testing this out, what this code actually gives you is this:

Six columns, a line, three columns

Hang on! Where are my two appended columns in the first block, the ones that should appear after the span-6 and before the colborder?

append-x and colborder don’t mix

To answer that I had to take a look at the Blueprint source code. As these three classes are to do with the layout grid these CSS rules span-6, append-2 and colborder are all defined in (my adapted) blueprint\src\grid.css:

58
59
60
.span-6 {
  width: 460px;
}
106
107
108
.append-2 {
  padding-right: 160px;
}
138
139
140
141
142
.colborder {
  padding-right: 49px;
  margin-right: 50px;
  border-right: 1px solid #eee;
}

So, in order:

  1. span-6 class is setting the width of the content to 460px.
  2. append-2 class is setting a padding-right of 160px.
  3. colborder is then overwriting padding-right with a width of 49px thereby making our appended two columns effectively disappear.

A new rule is required

I really wanted a solution that didn’t require any extra mark-up. Because I realised that this could be achieved with this code:

45
46
47
48
49
50
51
52
53
54
55
<div id="column1wrapper" class="span-8 colborder">
  <div id="column1" class="span-6 append-2">
    <h2>span-6 append-2</h2>
    <p>Lorem ipsum dolor sit amet, ... </p>
  </div>
</div>
 
<div id="column2" class="span-3 last">
  <h3>span-3 last</h3>
  <p>Lorem ipsum dolor sit amet, ... </p>
</div>

but that has an extra level of div tags.

After a little pondering, and a little scribbling on a scrap of paper, I realised that the solution lay in writing a new CSS rule that would prepend a colborder before the second block rather than append one after the first block.

In keeping with the append/prepend terminology of Blueprint I decided to call the new rule precolborder. The 12-columns version looks like this:

145
146
147
148
149
.precolborder {
  padding-left: 49px;
  margin-left: 29px;
  border-left: 1px solid #eee;
}

The 24-columns version (compatible with the default Blueprint CSS framework) looks like this:

165
166
167
168
169
170
171
/* Border with more whitespace on left hand side
    of a column, spans one column. */
.precolborder {
  padding-left: 24px;
  margin-left: 15px;
  border-left: 1px solid #eee;
}

and so our HTML now looks like this:

45
46
47
48
49
50
51
52
53
<div id="column1" class="span-6 append-2">
  <h2>span-6 colborder</h2>
  <p>Lorem ipsum dolor sit amet, ... </p>
</div>
 
<div id="column2" class="precolborder span-3 last">
  <h3>precolborder span-3 last</h3>
  <p>Lorem ipsum dolor sit amet, ... </p>
</div>

which looks like this on the rendered page:

Text spanning six columns, two blank columns, a border and then text spanning three columns

Which, if I’m not mistaken, is just what I wanted.

Feel free to use it if you like.

Maths

Okay, so I want to use the Blueprint CSS framework for a website I’m working on.

Page width is worked out with this formula:

Total width = (number_of_columns * column_width) – margin_width

So, I want a page width as close to 950px as possible, but able to divide equally into 7 sections (for the main navigation). By default there are 24 columns, each 40px wide (including a 10px margin).

The answer — after about an hour of tapping keys on my calculator — is a frustratingly simple 910px.

Or 23 columns.

I should have paid more attention in my Certificate of Sixth Year Studies maths class.

I wish maths classes had been more practical. Sure, I can do differential equations until the cows come home … but I’ve no idea when I would actually need to do them!