Super-fast Responsive Layouts with Jeet

There are plenty of grid systems available to us today. Designers and front-end developers can experiment with them and choose the ones that best fit their needs. CSS frameworks and boilerplates such as Bootstrap, Foundation, and Skeleton offer grids used by thousands of people.

In this article, I’d like to introduce you to Jeet, an alternative grid system built on CSS preprocessors. Firstly, I’ll cover the basics of it, presenting its core mixins. Then, I’ll show you how to build a project by taking advantage of its features.

What is Jeet

Jeet is a grid system built on top of Sass and Stylus. It consists of powerful mixins and functions you can use to create fast responsive layouts.

Unlike many other grids, Jeet provides a more flexible approach for producing layouts. Here are its main advantages:

  1. It doesn’t add any additional markup.
  2. It isn’t limited to a specific column size (e.g. 12-column grid).
  3. You can use fractions (e.g. 1/4), decimals (e.g. 0.75), or even a combination of them (e.g. 1.5/4) for generating the desired layout.

The grid is designed to work in all major browsers including IE9+. If you want to target previous versions of IE, take a look at the Boy boilerplate.

Getting Started

The grid comes in two flavors, one for Sass(SCSS) and another for Stylus. Depending on the preprocessor you want to use, there’s a different installation method. Jeet’s official page describes all the steps you should follow in order to include the grid in your projects.

Based on the Sass version of it, I set up a demo project. I’ll refer to it in an upcoming section. For now, let’s just look at its basic structure:

jeet-demo/
├── index.html
├── jeet/
│     ├── _functions.scss
│     ├── _grid.scss
│     ├── _settings.scss
│     └── index.scss
├── style.css
└── style.scss

You can grab all the files for this project by visiting this github repository.

At this point it’s time to go through Jeet’s major mixins.

Note: To demonstrate how the mixins work, I’ll use the SCSS syntax.

Container

The center mixin allows you to horizontally center an element. Most of the time, you’ll use this mixin to define the element that will act as the container of your columns. The table below shows its parameters:

Parameter Description Default Value
max-width Set the element’s max-width 1410px
pad Specify the padding-left and padding-right properties of the element 0

Here’s an example of that mixin:

See the Pen Jeet Grid – container by SitePoint (@SitePoint) on CodePen.

To restore the rules applied by the center mixin, use the uncenter mixin.

Columns with Gutters

To define your columns, Jeet provides the col or column mixin. The following table describes its parameters:

Parameter Description Default Value
ratios Set the element’s width relative to its container’s width 1
offset Specify the margin-left property of the element 0
cycle Define a nth (based on the cycle value) column grid 0
uncycle Undo the grid specified by the cycle variable 0
gutter Specify the margin-right property of the element 3

The cycle and uncycle variables simplify the process of creating multi-column responsive layouts. Here’s an example:

See the Pen Jeet Grid – columns with gutters by SitePoint (@SitePoint) on CodePen.

Columns without Gutters

In addition to the col/column mixin, there’s also available the span mixin for creating your columns. You can use this one in case you don’t want gutters between them. Here are its parameters:

Parameter Description Default Value
ratios Set the element’s width relative to its container’s width 1
offset Specify the margin-left property of the element 0
cycle Define a nth (based on the cycle value) column grid 0
uncycle Undo the grid specified by the cycle variable 0

Below is an example of that mixin:

See the Pen Jeet Grid – Columns without Gutters by SitePoint (@SitePoint) on CodePen.

Stacked Columns

The stack mixin helps you generate stacked columns. This is a handy feature, especially on small screen sizes, where the layout changes and the elements stack on top of each other. Here are its parameters:

Parameter Description Default Value
pad Specify the padding-left and padding-right properties of the element 0
align Set (if value=true) the element’s text-align property false

An example that takes advantage of that behavior is shown below:

See the Pen Jeet Grid – Stacked Columns by SitePoint (@SitePoint) on CodePen.

To restore the rules applied by the stack mixin, use the unstack one.

Column Ordering

Jeet provides the shift mixin for column ordering. The following table shows its parameters:

Parameter Description Default Value
ratios Specify how far the element will be moved compared to its original position 0
col-or-span Specify whether the element has a gutter or not column
gutter Specify the margin-right property of the element 3

You can get an idea of how this mixin works in the following example:

See the Pen Jeet Grid – Column Ordering by SitePoint (@SitePoint) on CodePen.

To restore the rules applied by the shift mixin, use the unshift one.

Absolute Centering

Using the align mixin you can center an element horizontally or/and vertically. In order to take advantage of it, you should also set the type of positioning of the parent element as relative.

The parameter of that mixin is shown below:

Parameter Description Default Value
direction Define the element’s type of alignment both

Here’s an example:

See the Pen Jeet Grid – Absolute Centering by SitePoint (@SitePoint) on CodePen.

Putting it All Together

Let’s now use Jeet to create the layout of our demo project.

First, we’ll structure the section related to our portfolio.

For small devices (<450px), we want the work items to be stacked. By default, that happens because in the markup we use the figure element, which is a block-level element. Moreover, when the browser window has a width between 450px and 799px, we want two items per row. Finally, for larger screens (≥800px) each row should contain four items.

Here’s our layout based on the last assumption:

Jeet Grid Example 1

Below is a snippet for the relevant HTML:

<div class="portfolio">
    <figure>
        <img src="http://placehold.it/450/ededed/ededed">
        <a href="#">
            <figcaption>Work-1</figcaption>
        </a>
    </figure>
    ...
</div>

Here’s our SCSS code:

@media screen and (min-width: 450px) {
    figure {
        @include col(1/2, $cycle: 2);
    }
}

@media screen and (min-width: 800px) {
    figure {
        @include col(1/4, $cycle: 4, $uncycle: 2);
    }
}

And the compiled CSS:

@media screen and (min-width: 450px) {
    figure {
        float: left;
        width: 48.5%;
        margin-left: 0%;
        margin-right: 3%;
    }

    figure:nth-of-type(2n) {
        float: right;
        margin-right: 0%;
    }
}

@media screen and (min-width: 800px) {
    figure {
        float: left;
        width: 22.75%;
        margin-left: 0%;
        margin-right: 3%;
    }

    figure:nth-of-type(2n) {
        float: left;
        margin-right: 3%;
    }

    figure:nth-of-type(4n) {
        float: right;
        margin-right: 0%;
    }
}

Note: For simplicity, I’ve only included some of the rules from the compiled CSS. To see the complete CSS that Jeet outputs, look at the style.css file.

Let’s work on a second example.

Here we will structure the social links. Each link will occupy one-fourth of their container width. To start, we define the width of their parent element using the center mixin. Then, we set their width taking advantage of the col mixin.

Here’s the desired layout:

Jeet Grid Example 2

Our markup:

<div>
    <a href="#">Twitter</a>
    ...
</div>

The required SCSS:

div {
    @include center(700px);

    a {
        @include col(1/4);
    }
}

And the resulting CSS:

div {
    max-width: 700px;
    margin-right: auto;
    margin-left: auto;
}

div a {
    float: left;
    width: 22.75%;
    margin-left: 0%;
    margin-right: 3%;
}

div a:last-child {
    margin-right: 0%;
}

Note: Again for simplicity, I’ve included just some of the rules from the compiled CSS. To see the complete CSS that Jeet outputs, look at the style.css file.

Conclusion

In this article, I presented Jeet, an alternative grid that helps you create easy and flexible responsive layouts. Then, I went through examples that demonstrated how to use its mixins. I hope you found the tour and this grid system interesting and you might give it a try in any of your upcoming projects.

If you’ve already used Jeet, let us know in the comments below.

Replies

  1. Could you explain this more? I don't quite understand it.

    The only time I see frameworks make yo uadd HTML is if you are implementing the grid. However, since most frameworks are based on floats, it's customary to add the parent just to contain the floated elements.

    I'm not sure what other examples you give that show it doesn't add additional markup (compared to other frameworks?)

    Could you be more specific? I couldn't quite pinpoint an example showcasing this main benefit.

    Other than that, I mean it's somewhat useful to have the custom sizes for the column size, but that's not exactly original; at my work we've modified the foundation CSS file to include some more specific sizes (only halves though) to help be more precise with our design.

    I'm not trying to be rude or anything; I just want to hear what makes this worth using smile . What stops, for example, my team from just using a framework and modifying it like we did (apposed to Jeet?) I'm sure we were not the first people to modify frameworks.

  2. Without jumping on Georges toes. I see Jeet not adding 'any additional markup' in light of something like Bootstrap or Zurb (both extremely popular frameworks (both of which George mentions at the top of the article)) and Harry Roberts' CSS Wizardry Grids that force you to include the grid within the markup. With the idea being you then put the actual HTML you're wanting to use within it.

    I haven't, personally, seen many grid systems that allow you to use fractions as well as decimals (and a combination of both) which, I feel, makes Jeet stand out a little more.

    Obviously there's nothing stopping you or your team from doing what you feel necessary for your work be it modify someone elses work to suit or deciding to write something from scratch.

    It'd be great if you could share your solution so everyone can benefit. I love looking and learning from how other people use Sass in their projects.

  3. I pitched an article to them (just an idea; I didn't say I'd write it) over 3 weeks ago, even sent Sitepoint a message on FB, and the survey that Sitepoint gave out, I EVEN sent it in there (with also a request to check their e-mail)) but STILL no one has responded. I'm a bit offended/shocked that no one appears to be checking their e-mail; or at the very least I didn't get a response.

    It wasn't a ground breaking article anyway; just something that I saw the internet lacked on.

  4. Hey Ryan — which address did you send your pitch to? I haven't gone through all survey results yet (there are a lot), but if you're still interested, you can pitch an article directly to me via PM here, or to @Adam, or to one of the SitePoint editors (like @sturobson or @louislazaris).

  5. Thanks, Stuart got in touch directly. And it turns out that it was 11/17/14 that I originally sent the e-mail so it's beyond 2 months; not 3 weeks like I thought stuck_out_tongue .

    I had e-mailed an undisclosed e-mail (don't want to say who I sent it to publicly) but I only pitched an idea; didn't want to actually write it myself. Those who have read my own website articles probably are frustrated at my writing smile .

    Back to the topic at hand...

    @georgemarts, I am able now to see what flexibility this offers. It saves some of the ground work that you'd have to otherwise do. I can appreciate how this will be useful. Thanks for the great article (although I'm holding true that I think it should have been explained better; but I'm just a disgruntled person since I didn't get it right away; that's my own fault)

    Keep up the good work.

    @Ophelie Stuart (in this thread) messaged me and I talked to him. If you really want to know who I sent it to, then you can follow up with him. I don't want the person to get in any trouble.

17 more replies