Git Product home page Git Product logo

neat's Introduction

Bourbon Neat

Gem Version Code Climate Gitter IRC

Neat is an open source fluid grid framework built on top of Bourbon with the aim of being easy enough to use out of the box and flexible enough to customize down the road.

⚠️ Neat 1.6.0 requires Sass 3.3.x. If you are using libsass or sass-rails use 1.5.1.

Requirements

  • Sass 3.3+
  • Bourbon 3.1+

Install Instructions

Install/update the dependencies first:

gem install sass #or gem update sass
gem install bourbon #or gem update bourbon

Install Neat:

gem install neat

Then cd to your Sass directory and run:

bourbon install #If not installed
neat install

In your main stylesheet:

@import "bourbon/bourbon";
@import "neat/neat";

To update Neat files, run:

neat update

and to remove them:

neat remove

Ruby on Rails

In your Gemfile:

gem 'neat'

After running bundle install you will be able to use Bourbon and Neat together.

If you see this error Bundler could not find compatible versions for gem "sass" run:

bundle update sass

Within your application.css.scss file place the following:

@import "bourbon";
@import "neat";

Getting started

First off, if you are planning to override the default grid settings (12 columns), it is recommended to create a _grid-settings.scss file for that purpose. Make sure to import it right before importing Neat:

@import "bourbon/bourbon"; // or "bourbon" when in Rails
@import "grid-settings";
@import "neat/neat"; // or "neat" when in Rails

In your newly created _grid-settings.scss, import neat-helpers if you are planning to use new-breakpoint(), then define your new variables:

@import "neat/neat-helpers"; // or "neat-helpers" when in Rails

// Change the grid settings
$column: 90px;
$gutter: 30px;
$grid-columns: 10;
$max-width: em(1088);

// Define your breakpoints
$tablet: new-breakpoint(max-width 768px 8);
$mobile: new-breakpoint(max-width 480px 4);

See the docs for a full list of settings.

Next, include the outer-container mixin in the topmost container (to which the max-width setting will be applied):

div.container {
  @include outer-container;
}

Then use span-columns on any element to specify the number of columns it should span:

div.element {
  @include span-columns(6);
}

If the element's parent isn't the top-most container, you need to add the number of columns of the parent element to keep the right proportions:

div.container {
  @include outer-container;
  div.parent-element {
    @include span-columns(8);
    div.element {
      @include span-columns(6 of 8);
    }
  }
}

To make your layout responsive, use the media() mixin to modify both the grid and the layout:

.my-class {
  @include media($mobile) { // As defined in _grid-settings.scss
    @include span-columns(2);
  }
}

// Compiled CSS
@media screen and (max-width: 480px) {
  .my-class {
    display: block;
    float: left;
    margin-right: 7.42297%;
    width: 46.28851%; // 2 columns of the total 4 in this media context
  }
  .my-class:last-child {
    margin-right: 0;
  }
}

By setting $visual-grid to true, you can display the base grid in the background (default) or as an overlay. You can even change the color and opacity of the grid-lines by overriding the default settings as detailed in the section below. Keep in mind that on Webkit, rounding errors in the fluid grid might result in the overlay being few pixels off.

The visual grid reflects the changes applied to the grid via the new-breakpoint() mixin, as long as the media contexts are defined before importing Neat.

Browser support

  • Firefox 3.5+
  • Safari 4.0+
  • Chrome 4.0+
  • Opera 9.5+
  • IE 9+ (Visual grid is IE10 only)
  • IE 8 with selectivizr (no media() support)

Frequently asked questions

How do I use omega() in a mobile-first workflow?

Using omega() with an nth-child pseudo selector in a mobile-first workflow will cause the style to be applied to wider-viewport media queries as well. That is the cascading nature of CSS.

One solution would be to provide an omega-reset() mixin that negates the effect of omega() on that specific nth-child pseudo selector. While this is often the most suggested solution, it is also a lazy hack that outputs ugly code and can quickly get out of hand in complex layouts. As a general rule, having to undo CSS styles is a sign of poor stylesheet architecture (More about CSS code smells).

The other, more elegant, solution is to use mutually exclusive media queries, also referred to as media-query splitting. This would guarantee that omega() styles are only applied where desired.

$first-breakpoint-value: 400px;
$second-breakpoint-value: 700px;
$medium-viewport: new-breakpoint(min-width em($first-breakpoint-value) max-width
em($second-breakpoint-value));
$large-viewport: new-breakpoint(min-width em($second-breakpoint-value + 1));

.element {
  @include media($medium-viewport) {
    @include span-columns(6);
    @include omega(2n);
  }

  @include media($large-viewport) {
    @include span-columns(4);
    @include omega(3n);
  }
}

If, for some reason, you still think that omega-reset is the only way you want to go, check out Josh Fry's omega-reset.

Framework X has this feature that Neat seems to be missing. Can you add it?

Unless you open a pull request, the answer is most likely going to be no. Neat is lightweight and simple compared to other grid frameworks, and strives to remain so. We have plans for adding new features in future versions of the framework, but these will be most likely to support new ways of working with layouts on the Web, not patches to existing ones.

Links

Credits & License

thoughtbot

Bourbon is maintained and funded by thoughtbot, inc. Follow @thoughtbot on Twitter.

Bourbon Neat is Copyright © 2012-2014 thoughtbot. It is free software, and may be redistributed under the terms specified in the LICENSE file.

neat's People

Contributors

andryusha avatar clooth avatar hakanensari avatar jimmynotjim avatar kittygiraudel avatar kylefiedler avatar mike-burns avatar nc avatar pusewicz avatar tmikoss avatar torbjon avatar vis-kid avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.