I'd like to talk to you about Lemonade. Not the refreshing citrus drink, but a grid system I created.
Lemonade is a grid system that was built in order to give designers and developers the confidence to make fully responsive websites, eliminating the frustration of flicking between browsers looking for bugs and errors. Let's look at how it's put together and how you can build your very own responsive grid system.
Before building my own, I often used Skeleton.css for my responsive layouts. However, as time went on, I felt like it was a bit of a lost cause, simply because I was constantly tweaking it to my needs and stripping away unnecessary elements that I felt weren't usable. It's a very good framework, but I would only recommend it to people who aren't comfortable with front-end work, at all.
There are so many grids, frameworks and libraries out there, but picking the right one is a tough decision. The easiest way to decide is by asking yourself "What am I trying to make?" For example: I'm currently building a CMS (mostly PHP) and I don't want to focus on the interface (the admin panel) at all, so I've opted for Bootstrap. Bootstrap is an amazingly comprehensive framework and literally takes care of you during every aspect of the design process.
Let me run you through these objectives in a more detailed manner. I wanted the grid to be tiny, so small that if I ever had to edit it, I wouldn’t be cursing at the screen with frustration. It needed to work on modern browsers (forget IE8 and under); I wanted to remove the scenario of flicking through browsers worrying if everything looks OK. The final objective was all about using it, I didn’t want to make something and just stick it on GitHub and never use it again. If I was going to create something, it would need to be used in every project that I made.
First let's tackle the CSS. Remember the first objective: “Be small, but powerful"
Essentially this is the grid’s backbone; this is what makes the grid function and holds the whole thing together.
Setting border-box with a universal selector keeps us from worrying about the padding of our elements messing with our widths.
Whilst we're on the subject of selectors, the biggest space killer in our grid is the attribute selector. You can see the attribute selctor in action where I've used [class*='bit-']. This targets any elements whose class attribute contains "bit-". We could also have used [class^='bit-'] which targets all elements where the class begins with "bit-". Using an attribute selector to encompass all our various column classes will save us so much time when writing new column widths.
Using the last-of-type selector we can target the last "bit-" element in the group, instructing it to float right, instead of left. This makes sure everything aligns perfectly against the right edge, in supporting browsers.
One common question I hear a lot about Lemonade is: “Why such weird class names?" It’s not an exciting story, I just kept referring to the columns as “bits" in my notes, so it kind of escalated from there. Saying that, I think I subconsciously wanted the classes to be different to the standard "col-1" seen in many other grid systems.
I generated the widths of the columns using a calculator (see, you don’t have to be a math nerd). Calculating the columns wasn't difficult at all, in fact it was really easy. For example, in my grid, each bit is a fraction of the whole width, bit-8 is an eighth. Therefore 100 ÷ 8 = 12.5, so we set the width of each bit-8 at 12.5%.
I thoroughly tested each column section with real content and they all function perfectly on different browsers and devices.
Now, as you can see, the widths are super clean, readable and this is what I initially wanted — you can easily see what’s what and if need be, you can mess around and edit the sizes with ease.
Yes. It looks a bit like a lemon.
These two in combination would be fine.
Making it responsive was pretty challenging, to get it perfect on every device and determine the breakpoints, was extremely frustrating. Let me run you through the code. I chose to work desktop down, rather than mobile first, but it's entirely up to you which approach you prefer.
We could loosely describe this as targeting Landscape Tablet to Desktop (though be aware that device widths are by no means set in stone). This was just as important as the other media queries - why? Because I found the majority of people who own 13" notebooks rarely have the browser full width, they will have it a couple of hundred pixels short of full-width, so what looks good on landscape tablet, must look good on desktop too.
This range I like to think of as targeting mobile to tablet (although, again, defining devices by screen resolution is rocky territory). Why the weird breakpoints? Nothing too crazy, it’s just what worked best — grids are very tedious when it comes to how strict the widths have to be, and I found these breakpoints worked well out in the wild.
The uniqueness of the column sizes was pretty tough to create and this was actually what I spent most of my research on; what do you usually see on desktop that changes dramatically on mobile? Mainly inline content that becomes stacked content - so I had to think what is more than likely going to be placed side-by-side and what will be stacked on top of each other.
This breakpoint addresses what most people would recognise as mobile. I tried to be more creative with setting the widths for mobile, but I felt I needed to keep it basic as I imagine most people aren't looking for some sort of metro layout or anything too crazy like that.
The HTML is super simple and that’s what's great about this grid. To carry on with our example, let’s make a three-grid column (could be a gallery, for example).
There you have it, a three-column responsive and browser compatible gallery. You can, of course, play around with the HTML and make all types of layouts.
Building Lemonade was a big learning curve for me, it taught me that if I’m not comfortable with something then I don’t have to stick around and wait for alternatives - I can create my own!
If you have any questions or issues, leave a comment below or feel free to tweet me.