In a world of agile development and super-tablet-multi-magic-laptop-phones, the best layouts can’t be contained in a single framework or technique. CSS Libraries are a bloated mess of opinions about how to do your job. Why let the table-saw tell you where to put the kitchen?
Your markup, your design, your opinions | our math.
注解
这些文档是针对Susy 2.2.9.如果想查看早期版本相关文档,请浏览 Susy One
Susy其实只需要 Sass 就行,但是Susy已经是 Compass 的一部分,另外 我们建议安装工具`Breakpoint`_和 Vertical Rhythms.
Susy One 语法中,Compass仍是必需的.
# command line
gem install susy
警告
In order to use Susy 2 with Rails you must update your Gemfile to use sass-rails ~> 5.0.0. This is because Susy 2 requires Sass >= 3.3 whilst Rails 4.1 and below include a version of sass-rails which does not support Sass 3.3.
# Gemfile
# gem 'sass-rails', '~> 4.0.3'
gem 'sass-rails', '~> 5.0.0'
gem 'susy'
# If you want Compass:
gem 'compass-rails', '~> 2.0.0'
# config/application.rb
require 'susy'
# command line
bundle install
If you add Susy to an existing Rails app, follow the steps above, but use bundle update instead of bundle install.
# command line
bundle update
If you want to use Susy with Compass, start by installing Compass.
Create a new Compass project:
# command line
compass create --using susy <project name>
Alternatively, add Susy to a current project
# command line
compass install susy
# command line
bower install susy --save
This will add the Susy repository to your bower_components directory or create a bower_components directory for you.
// Import Susy
@import "bower_components/susy/sass/susy";
You can also import Susyone.
// Import Susy
@import "bower_components/susy/sass/susyone";
You can enable Susy in Grunt by adding a line to your Gruntfile.js. You will need to add a line to either your Sass task or, if you’re using Compass, your Compass task.
To add Susy to the Sass task, edit your Gruntfile.js at the root level of your project and look for the Sass-related rules. Add require: 'susy' inside the options object:
// Gruntfile.js
sass: {
dist: {
options: {
style: 'expanded',
require: 'susy'
},
files: {
'css/style.css': 'scss/style.scss'
}
}
}
Assuming you’ve already installed Susy, it will now be added to the project and will not clash with Yeomans grunt rules.
To add Susy to the Compass task, edit your Gruntfile.js at the root level of your project and look for the Compass-related rules. Add require: 'susy' inside the options object:
// Gruntfile.js
compass: {
options: {
require: 'susy',
...
}
}
}
Again, assuming you’ve already installed Susy, it will now be added to the project.
Install using npm:
npm install susy sass-loader --save-dev
Make sure you have sass-loader enabled in your webpack configuration:
// webpack.config.js
loaders: [
{
test: /\.scss$/,
loader: 'style!css!sass'
}
]
Start using Susy:
/* app.scss */
@import "~susy/sass/susy";
If you want to copy in the Sass files directly, and skip any package management, you can do that too.
When you work with bundled gems across a number of different projects, managing gem versions can become an issue.
If you are in a Ruby environment, check out RVM. In a Python environment, we recommend virtualenv with these scripts added to your “postactivate” and “predeactivate” files.
Once you have that in place, Bundler can be used in either environment to manage the actual installation and updating of the gems.
Once you have everything installed, you can import Susy into your Sass files.
@import "susy";
The basic Susy layout is composed using two simple mixins:
@include container; // establish a layout context
@include span(<width>); // lay out your elements
For example:
body { @include container(80em); }
nav { @include span(25%); }
If you want to lay your elements out on a grid, you can use the span mixin to calculate column widths:
nav { @include span(3 of 12); }
But you don’t have to do things the Susy way. We give you direct access to the math, so you can use it any way you like:
main {
float: left;
width: span(4);
margin-left: span(2) + gutter();
margin-right: gutter();
}
You can also establish global settings, to configure Susy for your specific needs. Create a $susy variable, and add your settings as a map.
$susy: (
columns: 12, // The number of columns in your grid
gutters: 1/4, // The size of a gutter in relation to a single column
);
There are many more settings available for customizing every aspect of your layout, but this is just a quick-start guide. Keep going to get the details.
危险
这里小心!
The new syntax for Susy is based around a number of settings that can be written either as a Sass Map or using a 速记语法. 这两种设置的方法是可以交替使用的:
$susy: (
columns: 12,
gutters: 1/4,
math: fluid,
output: float,
gutter-position: inside,
);
$shorthand: 12 1/4 fluid float inside;
Either format can be passed as a single argument to the functions and mixins that make up the Susy language. Maps can even be used as part of the shorthand:
$susy: (
columns: 12,
gutters: .25,
math: fluid,
);
@include layout($susy float inside);
Unless otherwise noted, most settings can be controlled both globally (by setting the site-wide default) or locally (passed to individual functions and mixins).
下面是所有Susy的全局设置项及其默认值:
$susy: (
flow: ltr,
math: fluid,
output: float,
gutter-position: after,
container: auto,
container-position: center,
columns: 4,
gutters: .25,
column-width: false,
global-box-sizing: content-box,
last-flow: to,
debug: (
image: hide,
color: rgba(#66f, .25),
output: background,
toggle: top right,
),
use-custom: (
background-image: true,
background-options: false,
box-sizing: true,
clearfix: false,
rem: true,
)
);
你可以定义自己的全局默认配置, or create individual layout maps to access as needed.
想全局设置,只需定义一个变量 $susy ,格式如下
$susy: (
columns: 12,
gutters: .25,
gutter-position: inside,
)
A “layout” in Susy is made up of any combination of settings. Layouts are stored as maps, but can also be written as shorthand.
Convert shorthand into a map of settings.
Format: | layout($layout) |
---|---|
$layout: | <layout> |
// function input
$map: layout(auto 12 .25 inside fluid isolate);
//output
$map: (
container: auto,
columns: 12,
gutters: .25,
gutter-position: inside,
math: fluid,
output: isolate,
);
This is useful any time you need to combine settings stored in different variables. It’s not possible to combine two shorthand variables:
// THIS WON'T WORK
$short: 12 .25 inside;
@include layout($short fluid no-gutters);
but it is possible to add a map into the shorthand:
// THIS WILL WORK
$map: layout(12 .25 inside);
@include layout($map fluid no-gutters);
or combine two maps:
$map1: 13 static;
$map2: (6em 1em) inside;
@include layout($map1 $map2);
Set a new layout as the global default.
Format: | layout($layout, $clean) |
---|---|
$layout: | <layout> |
$clean: | <boolean> |
// mixin: set a global layout
@include layout(12 1/4 inside-static);
By default, these new settings are added to your existing global settings. Use the $clean argument to establish new settings from scratch.
Temporarily set defaults for a section of your code.
Format: | with-layout($layout, $clean) { @content } |
---|---|
$layout: | <layout> |
$clean: | <boolean> |
@content: | Sass content block |
@include with-layout(8 static) {
// Temporary 8-column static grid...
}
// Global settings are restored...
By default, these new settings are added to your existing global settings. Use the $clean argument to establish new settings from scratch.
Format: | susy-get($key, $layout) |
---|---|
$key: | Setting name |
$layout: | <layout> |
You can access your layout settings at any time, using the susy-get function.
$large: layout(80em 24 1/4 inside);
$large-container: susy-get(container, $large);
To access a nested setting like debug/image, send the full path as a list for the $key argument.
$debug-image: susy-get(debug image);
If no setting is available (or no $layout is provided) susy-get falls back to the global user settings, and finally to the Susy default settings.
The reading direction of your document. Layout elements will stack out in the direction of flow, unless otherwise directed.
Key: | flow |
---|---|
Scope: | global, local |
Options: | rtl | ltr |
Default: | ltr |
Susy can produce either relative widths (fluid percentages) or static widths (using given units).
Key: | math |
---|---|
Scope: | global, local |
Options: | fluid | static |
Default: | fluid |
Susy can generate output using different layout techniques. Currently we have a float module, with an extension to handle isolation as well. In the future there could be flexbox, grid, and other output styles.
Key: | output |
---|---|
Scope: | global, local |
Options: | float | isolate |
Default: | float |
Set the max-width of the containing element.
Key: | container |
---|---|
Scope: | global, local [container only] |
Options: | <length> | auto |
Default: | auto |
警告
For static layouts, leave container: auto and set the column-width instead. Susy will calculate the outer container width for you. Dividing columns out of a set container width would leave you open to sub-pixel errors, and no one likes sub-pixel errors.
Align the container relative to it’s parent element (often the viewport).
Key: | container-position |
---|---|
Scope: | global, local [container only] |
Options: | left | center | right | <length> [*2] |
Default: | center |
Establish the column-count and arrangement for a grid.
Key: | columns |
---|---|
Scope: | global, local |
Options: | <number> | <list> |
Default: | 4 |
Set the width of a gutter relative to columns on your grid.
Key: | gutters |
---|---|
Scope: | global, local |
Options: | <ratio> |
Default: | 1/4 |
Gutters are established as a ratio to the size of a column. The default 1/4 setting will create gutters one quarter the size of a column. In asymmetrical grids, this is 1/4 the size of a single column-unit.
If you want to set explicit column and gutter widths, write your gutters setting as <gutter-width>/<column-width>. You can even leave the units attached.
// 70px columns, 20px gutters
$susy: (
gutters: 20px/70px,
);
Optionaly set the explicit width of a column.
Key: | column-width |
---|---|
Scope: | global, local |
Options: | <length> | false/null |
Default: | false |
Set how and where gutters are added to the layout, either as padding or margins on layout elements.
Key: | gutter-position |
---|---|
Scope: | global, local |
Options: | before | after | split | inside | inside-static |
Default: | after |
Tell Susy what box model is being applied globally.
Key: | global-box-sizing |
---|---|
Scope: | global |
Options: | border-box | content-box |
Default: | content-box |
For more, see the MDN box-sizing documentation.
The float-direction for the last element in a row when using the float output.
Key: | last-flow |
---|---|
Scope: | global |
Options: | from | to |
Default: | to |
Susy has a few tools to help in debugging your layout as you work. These settings help you control the debugging environment.
Key: | debug |
---|---|
Scope: | global, local [container only] |
Options: | <map of sub-settings> |
$susy: (
debug: (
image: show,
color: blue,
output: overlay,
toggle: top right,
),
);
警告
Grid images are not exact. Browsers have extra trouble with sub-pixel rounding on background images. These are meant for rough debugging, not for pixel-perfect measurements. Expect the to side of your grid image (right if your flow is ltr) to be off by several pixels.
Toggle the available grid images on and off.
Key: | debug image |
---|---|
Scope: | global, local [container only] |
Options: | show | hide | show-columns | show-baseline |
Default: | hide |
The debug image can be output either as a background on the container, or as a generated overlay.
Key: | debug output |
---|---|
Scope: | global, local [container only] |
Options: | background | overlay |
Default: | background |
If you are using the grid overlay option, Susy will generate a toggle to show/hide the overlay. Hovering over the toggle will show the overlay. You can place the toggle in any corner of the viewport using a combination of top, right, bottom, and left.
Key: | debug toggle |
---|---|
Scope: | global |
Options: | right | left and top | bottom |
Default: | top right |
Change the color of columns in the generated grid image.
Key: | debug color |
---|---|
Scope: | global |
Options: | <color> |
Default: | rgba(#66f, .25) |
There are several common helpers that you can tell Susy to use, if you provide them yourself or through a third-party library like Compass or Bourbon.
Tell Susy to use a global clearfix mixin.
Key: | use-custom clearfix |
---|---|
Scope: | global |
Options: | <boolean> |
Default: | false |
Tell Susy to use a global background-image mixin. This is only used for debugging.
Key: | use-custom background-image |
---|---|
Scope: | global |
Options: | <boolean> |
Default: | true |
Tell Susy to use global background-size, -origin, and -clip mixins. This is only used for debugging.
Key: | use-custom background-options |
---|---|
Scope: | global |
Options: | <boolean> |
Default: | false |
Tell Susy to use a custom breakpoint mixin, like the one provided by the Breakpoint plugin.
Key: | use-custom breakpoint |
---|---|
Scope: | global |
Options: | <boolean> |
Default: | true |
Tell Susy to use a global box-sizing mixin.
Key: | use-custom box-sizing |
---|---|
Scope: | global |
Options: | <boolean> |
Default: | true |
Tell Susy to use the Compass rem support module.
Key: | use-custom rem |
---|---|
Scope: | global |
Options: | <boolean> |
Default: | true |
Reference a specific column on the grid for row edges, isolation, or asymmetrical layouts. Locations keywords don’t require the at flag.
Key: | location |
---|---|
Scope: | local |
Options: | first/alpha | last/omega | <number> |
Default: | null |
Set a new box model on any given element.
Key: | box-sizing |
---|---|
Scope: | local |
Options: | border-box | content-box |
Default: | null |
Adjust how many gutters are included in a column span.
Key: | spread |
---|---|
Scope: | local |
Options: | narrow | wide | wider |
Default: | various... |
Set an explicit one-off gutter-width on an element, or remove its gutters entirely.
Key: | gutter-override |
---|---|
Scope: | local |
Options: | no-gutters/no-gutter | <length> |
Default: | null |
Mark a grid element as a nesting context for child elements.
Key: | role |
---|---|
Scope: | local |
Options: | nest |
Default: | null |
注解
This can be used with any grid type, but it is required for nesting with split, inside, or inside-static gutters.
Susy使用了一种速记语法,这样很容易地向函数(function)和混合(mixin)传递任意数量的设置. This allows the syntax to stay simple and readable for the majority of use cases, and only add complexity if/when you really need it.
// 生成一个宽度为80em的容器
@include container(80em);
// Span 3 of 12 columns
@include span(3 of 12);
// Setup the 960 Grid System
@include layout(12 (60px 20px) split static);
// Span 3 isolated columns in a complex, asymmetrical grid, without gutters
@include span(isolate 3 at 2 of (1 2 3 4 3 2 1) no-gutters);
在大多数情况下,语法顺序并不重要,但有一些规则要注意。语法一般分为三个部分。
Shorthand: | $span $grid $keywords; |
---|
The grid is composed of a Columns setting, and optional settings for Gutters and Column Width. It looks something like this:
// 12-column grid
$grid: 12;
// 12-column grid with 1/3 gutter ratio
$grid: 12 1/3;
// 12-column grid with 60px columns and 10px gutters
$grid: 12 (60px 10px);
// asymmetrical grid with .25 gutter ratio
$grid: (1 2 3 2 1) .25;
The keywords are the easiest. Most settings have simple keyword values that can be included in any order — before, after, or between the span and grid options.
// All the keywords in Susy:
$global-keywords: (
container : auto,
math : static fluid,
output : isolate float,
container-position : left center right,
flow : ltr rtl,
gutter-position : before after split inside inside-static,
debug: (
image : show hide show-columns show-baseline,
output : background overlay,
),
);
$local-keywords: (
box-sizing : border-box content-box,
edge : first alpha last omega,
spread : narrow wide wider,
gutter-override : no-gutters no-gutter,
clear : break nobreak,
role : nest,
);
The global keywords can be used anywhere, and apply to global default settings. The local keywords are specific to each individual use.
The simplest shorthand variation is used for defining your layout in broad terms.
Pattern: | <grid> <keywords> |
---|
Nothing here is required — all the settings are optional and have global defaults. grid and keyword settings work exactly as advertised.
// grid: (columns: 4, gutters: 1/4, column-width: 4em);
// keywords: (math: fluid, gutter-position: inside-static, flow: rtl);
$small: 4 (4em 1em) fluid inside-static rtl;
You can easily convert layouts from shorthand to map syntax using the 布局 function.
Most of Susy’s functions & mixins are used to calculate or set a width, or span.
Pattern: | <span> at <location> of <layout> |
---|
Most spans in Susy are either a unitless number (representing columns) or an explicit width. Some of them also require a location (particularly for asymmetrical grids and isolation).
The standard span syntax looks like this:
// Pattern:
$span: $span at $location of $layout;
// span: 3;
// location: 4;
// layout: (columns: 12, gutters: .25, math: fluid)
$span: 3 at 4 of 12 .25 fluid;
// Only $span is required in most cases
$span: 30%;
The “at” flag comes immediately before the location (unless the location itself is a keyword), and everything after the “of” flag is treated as part of the layout.
Some mixins accept multiple spans, using the common CSS “top right bottom left” (TRBL) pattern, or have other specific options. Those are all documented as part of the function/mixin details.
The Susy 2.0 toolkit is built around our shorthand syntax. Use the shorthand to control every detail, and adjust your defaults on-the-fly, so you are never tied down to just one grid, or just one output style.
Set any element to span a portion of your layout. For a floated or isolated layout, this will add necessary floats, widths, and margins.
Format: | span($span) { @content } |
---|---|
$span: | <span> |
@content: | Sass content block |
There are many ways to use the span mixin...
For the simplest use, pass any width directly to the mixin:
// arbitrary width
.item { @include span(25%); }
// float output (without gutters)
.item {
float: left;
width: 25%;
}
If you are using a grid, you can also span columns on the grid:
// grid span
.item { @include span(3); }
// output (7-column grid with 1/2 gutters after)
.item {
float: left;
width: 40%;
margin-right: 5%;
}
When you use a grid with gutters before or after, you sometimes need to mark the first or last elements in a row, so Susy can remove the extra gutters:
// grid span
@include span(last 3);
// output (same 7-column grid)
.item {
float: right;
width: 40%;
margin-right: 0;
}
For legacy reasons, alpha and omega can be used in place of first and last.
Context is required any time you are using fluid math, and nesting grid elements inside other elements:
// 10-column grid
.outer {
@include span(5);
.inner { @include span(2 of 5); }
}
The of flag is used to signal context. The context is always equal to the grid-span of the parent. In some cases, you can imply changes in context by nesting elements inside the span tag itself:
// 10-column grid
.outer {
// out here, the context is 10
@include span(5) {
// in here, the context is 5
.inner { @include span(2); }
}
}
Grids with inside, inside-static, or split gutters don’t need to worry about the edge cases, but they do have to worry about nesting.
If an element will have grid-aligned children, you should mark it as a nest:
// inside, inside-static, or split gutters
.outer {
@include span(5 nest);
.inner { @include span(2 of 5); }
}
Asymmetrical grids and isolated output also need to know the desired location of the span. In both cases, use the at flag to set a location.
For isolation, you can use either an arbitrary width or a column index (starting with 1). For asymmetrical grid spans, the location setting must be a column index:
.width { @include span(isolate 500px at 25%); }
.index { @include span(isolate 3 at 2); }
By default, a grid span only spans the gutters between columns. So a span of 2 includes 1 internal gutter (narrow). In some cases you want to span additional gutters on either side. So that same span of 2 could include the internal gutter, and one (wide) or both (wider) external gutters.
// grid span
.narrow { @include span(2); }
.wide { @include span(2 wide); }
.wider { @include span(2 wider); }
// width output (7 columns, .25 gutters)
// (each column is 10%, and each gutter adds 2.5%)
.narrow { width: 22.5%; }
.wide { width: 25%; }
.wider { width: 27.5%; }
If you are using inside gutters, the spans are wide by default but can be overridden manually.
Use the full keyword to span the entire context available, use break to start a new Rows & Edges by clearing previous floats, and nobreak to clear none. Use no-gutters to remove gutter output from an individual span, and use border-box or content-box to output changes in box-sizing on the fly.
You can set an arbitrary gutter override, by passing a map (e.g. (gutter-override: 1.5em)) as part of the shorthand syntax.
You can also change the output style, grid context, and other global settings on the fly:
// grid span
.item { @include span(isolate 4 at 2 of 8 (4em 1em) inside rtl break); }
// output
.item {
clear: both;
float: right;
width: 50%;
padding-left: .5em;
padding-right: .5em;
margin-left: 25%;
margin-right: -100%;
}
The span function is identical to the span mixin, but returns only the span width value, so you can use it with custom output.
Format: | span($span) |
---|---|
$span: | <span> |
.item {
width: span(2);
margin-left: span(3 wide);
margin-right: span(1) + 25%;
}
Format: | gutters($span) |
---|---|
Alternate: | gutter($span) |
$span: | <span> |
Use gutter or gutters as a function to return the width of a gutter given your settings and current context.
// default context
margin-left: gutter();
// nested in a 10-column context
margin-left: gutter(10);
Use the mixin version to apply gutters to any element. Gutters are output as margin or padding depending on the gutter-position setting.
// default gutters
.item { @include gutters; }
You can also set explicit gutter widths:
// explicit gutters
.item { @include gutters(3em); }
Or use the shorthand syntax to adjust settings on the fly:
// inside gutters
.item { @include gutters(3em inside); }
// gutters after, in an explicit (10 1/3) layout context
.item { @include gutters(10 1/3 after); }
Format: | container($layout) |
---|---|
$layout: | <layout> |
Use the container function to return a container-width based on an optional layout argument, or your global settings.
// global settings
width: container();
// 12-column grid
$large-breakpoint: container(12);
Use the mixin to apply container settings to an element directly.
body {
@include container(12 center static);
}
Note that static math requires a valid column-width setting
Function: | nested($span) |
---|---|
Mixin: | nested($span) { @content } |
$span: | <span> |
@content: | Sass content block |
Sass is not aware of the DOM, or the specific markup of your site, so Susy mixins don’t know about any ancestor/child relationships. If your container creates a grid context that is different from the default, you will need to pass that new context explicitly to nested elements.
You can pass that context along with the shorthand syntax.
body { @include container(8); }
.span { @include span(3 of 8); }
But that gets repetitive if you have large blocks of code using a given context. The nested mixin provides a shortcut to change the default context for a section of code.
@include nested(8) {
.span { @include span(3); }
}
Context is a bit more complex when you are using asymmetrical grids, because we need to know not just how many columns, but which columns are available.
.outer {
@include span(3 of (1 2 3 2 1) at 2);
// context is now (2 3 2)...
.inner { @include span(2 of (2 3 2) at 1); }
}
The nested function can help you manage context more easily, without having to calculate it yourself.
$grid: (1 2 3 2 1);
.outer {
@include span(3 of $grid at 2);
$context: nested(3 of $grid at 2);
.inner { @include span(2 of $context at 1); }
}
Set the box-sizing on a global selector, and set the global-box-sizing to match.
Format: | global-box-sizing($box [, $inherit]) |
---|---|
Shortcut: | border-box-sizing([$inherit]) |
$box: | content-box | border-box |
$inherit: | [optional] true | false |
Setting the optional argument, $inherit, to true will still globally set the box-sizing, but in a way such that a component can easily override the global box-sizing by setting its own box-sizing property. By setting box-sizing once on the component, all nested elements within the component will also be modified. The default behavior, where $inherit is false, would only update the box-sizing of the component itself. Nested elements are not affected when $inherit is false.
You can pass a box-sizing argument to the span mixin as part of the shorthand syntax, and Susy will set the element’s box-sizing to match.
// input
.item { @include span(25em border-box); }
// sample output (depending on settings)
.item {
float: left;
width: 25em;
box-sizing: border-box;
}
We highly recommend using a global border-box setting, especially if you are using inside gutters of any kind.
// the basics with default behavior:
* { box-sizing: border-box; }
// the basics with $inherit set to true:
html { box-sizing: border-box; }
* { box-sizing: inherit; }
Susy needs to know what box model you are using, so the best approach is to set global box sizing using one of Susy’s shortcuts.
// the flexible version:
@include global-box-sizing(border-box);
// the shortcut:
@include border-box-sizing;
If you want to change the global box-sizing by hand, or it has already been changed by another library, update the global-box-sizing setting to let Susy know.
If you need to supprot IE6/7, there is a simple polyfill to make it work.
Floated layouts sometimes require help maintaining rows and edges.
Format: | break() |
---|---|
Reset: | nobreak() |
Keywords: | break | nobreak |
To create a new row, you need to clear all previous floats. This can usually be done using keywords with the span mixin. When you need to apply a row-break on it’s own, we have a break mixin.
.new-line { @include break; }
If you ever need to override that, you can use nobreak to set clear: none;.
.no-new-line { @include nobreak; }
Both break and nobreak can also be used as keywords with the span mixin.
Format: | first($context) |
---|---|
Alternate: | alpha($context) |
$context: | <layout> |
注解
Only useful when gutter-position is set to before.
When gutter-position is set to before we need to remove the gutter from the first element in every row. This can often be solved using a keyword in the span mixin. Sometimes you need to set an item as first outside the span mixin.
.first { @include first; }
We also support an alpha mixin with the same syntax and output.
Both first and alpha can also be used as keywords with the span mixin.
Format: | last($context) |
---|---|
Alternate: | omega($context) |
$context: | <layout> |
注解
Only required when gutter-position is set to after, but can be useful in any context to help with sub-pixel rounding issues.
When gutter-position is set to after we need to remove the gutter from the last element in every row, and optionally float in the opposite direction. This can often be solved using a keyword in the span mixin. Sometimes you need to set an item as last outside the span mixin.
.last { @include last; }
We also support an omega mixin with the same syntax and output.
Both last and omega can also be used as keywords with the span mixin.
Format: | full($context) |
---|---|
$context: | <layout> |
This is a shortcut for span(full), used to create elements that span their entire context.
.last { @include full; }
full can also be used as a keyword with the span mixin.
Shortcut mixins for applying left/right margins.
Format: | pre($span) |
---|---|
Alternate: | push($span) |
$span: | <span> |
Add margins before an element, depending on the flow direction.
.example1 { @include pre(25%); }
.example2 { @include push(2 of 7); }
Format: | post($span) |
---|---|
$span: | <span> |
Add margins after an element, depending on the flow direction.
.example1 { @include post(25%); }
.example2 { @include post(2 of 7); }
Format: | pull($span) |
---|---|
$span: | <span> |
Add negative margins before an element, pulling it against the direction of flow.
.example1 { @include pull(25%); }
.example2 { @include pull(2 of 7); }
Shortcut for adding both pre and post margins to the same element.
// equal pre and post
.example1 { @include squish(25%); }
// distinct pre and post
.example2 { @include squish(1, 3); }
When they share identical context, you can pass pre and post spans in the same argument. This is often the case, and saves you from repeating yourself.
// shared context
.shared {
@include squish(1 3 of 12 no-gutters);
}
// distinct context
.distinct {
@include squish(1 at 2, 3 at 6);
}
Shortcut mixins for applying left/right padding.
注解
The interaction between padding and width changes depending on your given box-model. In the browser-default content-box model, width and padding are added together, so that an item with span(3) and prefix(2) will occupy a total of 5 columns. In the recommended border-box model, padding is subtracted from the width, so that an item with span(3) will always occupy 3 columns, no matter what padding is applied.
Format: | prefix($span) |
---|---|
$span: | <span> |
Add padding before an element, depending on the flow direction.
.example1 { @include prefix(25%); }
.example2 { @include prefix(2 of 7); }
Format: | suffix($span) |
---|---|
$span: | <span> |
Add padding after an element, depending on the flow direction.
.example1 { @include suffix(25%); }
.example2 { @include suffix(2 of 7); }
Shortcut for adding both prefix and suffix padding to the same element.
// equal pre and post
.example1 { @include pad(25%); }
// distinct pre and post
.example2 { @include pad(1, 3); }
When they share identical context, you can pass pre and post spans in the same argument. This is often the case, and saves you from repeating yourself.
// shared context
.shared {
@include pad(1 3 of 12 no-gutters);
}
// distinct context
.distinct {
@include pad(1 at 2, 3 at 6);
}
Format: | bleed($bleed) |
---|---|
$bleed: | TRBL <span> |
Apply negative margins and equal positive padding, so that element borders and backgrounds “bleed” outside of their containers, without the content be affected.
This uses the standard span shorthand, but takes anywhere from one to four widths, using the common TRBL pattern from CSS.
// input
.example1 { @include bleed(1em); }
.example2 { @include bleed(1em 2 20px 5% of 8 .25); }
// output
.example1 {
margin: -1em;
padding: 1em;
}
.example2 {
margin-top: -1em;
padding-top: 1em;
margin-right: -22.5%;
padding-right: 22.5%;
margin-bottom: -20px;
padding-bottom: 20px;
margin-left: -5%;
padding-left: 5%;
}
When possible, the bleed mixins will attempt to keep gutters intact. Use the no-gutters keyword to override that behavior.
Format: | isolate($isolate) |
---|---|
$isolate: | <span> |
Isolation is a layout technique based on floats, but adjusted to address sub-pixel rounding issues. Susy supports it as a global output setting, or as a 速记Shorthand keyword for the span mixin, or as a stand-alone mixin.
The $isolate argument takes a standard span shorthand, but any length or grid-index given is interpreted as an isolation location (unless location is otherwise specified with the at flag). The function returns a length value.
// input
.function {
margin-left: isolate(2 of 7 .5 after);
}
// output
.function {
margin-left: 15%;
}
And the mixin returns all the properties required for isolation.
// input
.mixin { @include isolate(25%); }
// output
.mixin {
float: left;
margin-left: 25%;
margin-right: -100%;
}
Format: | gallery($span, $selector) |
---|---|
$span: | <span> |
$selector: | (nth-) child* | of-type |
Gallery is a shortcut for creating gallery-style layouts, where a large number of elements are laid out on a consistent grid. We take the standard span shorthand and apply it to all the elements, using nth-child or nth-of-type selectors and the isolation technique to arrange them on the grid.
// each img will span 3 of 12 columns,
// with 4 images in each row:
.gallery img {
@include gallery(3 of 12);
}
警告
The nth-child selector has issues on iOS8 Safari. Use nth-of-type for iOS8 support.
Format: | show-grid($grid) |
---|---|
$grid: | <layout> |
The easiest way to show you grids is by adding a keyword to your container mixin. If you need to apply the grid separately, the show-grid mixin takes exactly the same layout shorthand arguments, and can output the debugging grid image as either a background, or a triggered overlay.
body {
@include container;
@include show-grid(overlay);
}
警告
Grid images are not exact. Browsers have extra trouble with sub-pixel rounding on background images. These are meant for rough debugging, not for pixel-perfect measurements. Expect the to side of your grid image (right if your flow is ltr) to be off by several pixels.
Susy has built-in media-query handling, and also supports integration with the Breakpoint plugin. To install Breakpoint, follow the instuctions on their site.
Format: | susy-breakpoint($query, $layout, $no-query) |
---|---|
$query: | media query shorthand (see susy-media) |
$layout: | <layout> |
$no-query: | <boolean> | <string> (see susy-media) |
susy-breakpoint() acts as a shortcut for changing layout settings at different media-query breakpoints, using either susy-media or the third-party Breakpoint plugin.
If you are using the third-party plugin, see Breakpoint: Basic Media Queries and Breakpoint: No Query Fallbacks for details.
This mixin acts as a wrapper, adding media-queries and changing the layout settings for any susy functions or mixins that are nested inside.
@include susy-breakpoint(30em, 8) {
// nested code uses an 8-column grid,
// starting at a 30em min-width breakpoint...
.example { @include span(3); }
}
Format: | susy-media($query, $no-query) |
---|---|
$query: | <min-width> [<max-width>] | <string> | <pair> | <map> |
$no-query: | <boolean> | <string> |
The susy-media mixin provides basic media-query handling, and handles the built-in functionality for susy-breakpoint.
// min
// ---
@include susy-media(30em) { /*...*/ }
@media (min-width: 30em) { /*...*/ }
// min/max pair
// ------------
@include susy-media(30em 60em) { /*...*/ }
@media (min-width: 30em) and (max-width: 60em) { /*...*/ }
// property/value pair
// -------------------
@include susy-media(min-height 30em) { /*...*/ }
@media (min-height: 30em) { /*...*/ }
// map
// ---
@include susy-media((
min-height: 30em,
orientation: landscape,
)) { /*...*/ }
@media (min-height: 30em) and (orientation: landscape) { /*...*/ }
true will render the contents to css without any media-query. This can be useful for creating separate no-query fallback files.
For inline fallbacks using a target class, pass in a string (e.g. .no-mqs) to use as your fallback selector. The contents will be output both inside a media-query and again inside the given selector.
This can be set globally with the $susy-media-fallback variable.
susy-media also supports named media-queries, which can be set using the $susy-media variable:
$susy-media: (
min: 20em,
max: 80em 60em,
string: 'screen and (orientation: landscape)',
pair: min-height 40em,
map: (
media: screen,
max-width: 30em
),
);
@include susy-media(min);
This is documentation for the old syntax, used in Susy 1.
If you are using Susy 2 and want use the old syntax, change your import from susy to susyone.
// With Susy 2 installed...
@import "susyone";
The number of Columns in your default Grid Layout.
// $total-columns: <number>;
$total-columns: 12;
The width of a single Column in your Grid.
// $column-width: <length>;
$column-width: 4em;
The space between Columns.
// $gutter-width: <length>;
$gutter-width: 1em;
Padding on the left and right of a Grid Container.
// $grid-padding: <length>;
$grid-padding: $gutter-width; // 1em
Where a mixin returns property/value pairs, functions return simple values that you can put where you want, and use for advanced math.
Similar to span-columns mixin, but returns the math-ready % multiplier.
// columns(<$columns> [, <$context>, <$style>])
.item { width: columns(3,6); }
The % width of one gutter in any given context.
// gutter([<$context>, <$style>])
.item { margin-right: gutter(6) + columns(3,6); }
Total % space taken by Columns, including internal AND external gutters.
// space(<$columns> [, <$context>, <$style>])
.item { margin-right: space(3,6); }
Establish the outer grid-containing element.
// container([$<media-layout>]*)
.page { @include container; }
Align an element to the Susy Grid.
// span-columns(<$columns> [<omega> , <$context>, <$padding>, <$from>, <$style>])
nav { @include span-columns(3,12); }
article { @include span-columns(9 omega,12); }
Apply to any omega element as an override.
// omega([<$from>])
.gallery-image {
@include span-columns(3,9); // each gallery-image is 3 of 9 cols.
&:nth-child(3n) { @include omega; } // every third image completes a row.
}
Apply to any element as an nth-child omega shortcut. Defaults to :last-child.
// nth-omega([<$n>, <$selector>, <$from>])
.gallery-image {
@include span-columns(3,9); // each gallery-image is 3 of 9 cols.
@include nth-omega(3n); // same as omega example above.
}
// $media-layout: <min-width> <layout> <max-width> <ie-fallback>;
// - You must supply either <min-width> or <layout>.
$media-layout: 12; // Use 12-col layout at matching min-width.
$media-layout: 30em; // At min 30em, use closest fitting layout.
$media-layout: 30em 12; // At min 30em, use 12-col layout.
$media-layout: 12 60em; // Use 12 cols up to max 60em.
$media-layout: 30em 60em; // Between min 30em & max 60em, use closest layout.
$media-layout: 30em 12 60em;// Use 12 cols between min 30em & max 60em.
$media-layout: 60em 12 30em;// Same. Larger length will always be max-width.
$media-layout : 12 lt-ie9; // Output is included under ``.lt-ie9`` class,
// for use with IE conditional comments
// on the <html> tag.
At a given min- or max-width Breakpoint, use a given Layout.
// at-breakpoint(<$media-layout> [, <$font-size>]) { <@content> }
@include at-breakpoint(30em 12) {
.page { @include container; }
}
Set an arbitrary Layout to use with any block of content.
// layout(<$layout-cols>) { <@content> }
@include layout(6) {
.narrow-page { @include container; }
}
Reset the width of a Container for a new Layout context. Can be used when container() has already been applied to an element, for DRYer output than using container again.
// set-container-width([<$columns>, <$style>])
@include container;
@include at-breakpoint(8) {
@include set-container-width;
}
Use different grid settings for a block of code - whether the same grid at a different breakpoint, or a different grid altogether.
// with-grid-settings([$<columns>, $<width>, <$gutter>, <$padding>]) { <@content> }
@include with-grid-settings(12,4em,1.5em,1em) {
.new-grid { @include container; }
};
Set the default box-model to border-box, and adjust the grid math accordingly.
// border-box-sizing()
@include border-box-sizing;
This will apply border-box model to all elements (using the star selector) and set $border-box-sizing to true. You can use the variable on it’s own to adjust the grid math, in cases where you want to apply the box-model separately.
Isolate the position of a grid element relative to the container. This should be used in addition to span-columns as a way of minimizing sub-pixel rounding errors in specific trouble locations.
// isolate(<$location> [, <$context>, <$from>, <$style>])
@include span-columns(4); // 4-columns wide
@include isolate(2); // positioned in the second column
Isolate a group of elements in a grid (such as an image gallery) using nth-child or nth-of-type for positioning. Provide the column-width of each element, and Susy will determine the positioning for you.
// isolate-grid(<$columns> [, <$context>, <$selector>, <$from>, <$style>])
.gallery-item {
@include isolate-grid(3);
}
Add Columns of empty space as padding before an element.
// prefix(<$columns> [, <$context>, <$from>, <$style>])
.box { @include prefix(3); }
Add columns of empty space as padding after an element.
// suffix(<$columns> [, <$context>, <$from>, <$style>])
.box { @include suffix(2); }
Shortcut for adding both Prefix and Suffix padding.
// pad([<$prefix>, <$suffix>, <$context>, <$from>, <$style>])
.box { @include pad(3,2); }
Add negative margins and matching positive padding to an element, so that its background “bleeds” outside its natural position.
// bleed(<$width> [<$sides>, <$style>])
@include bleed(2);
Add columns of empty space as margin before an element.
// pre(<$columns> [, <$context>, <$from>, <$style>])
.box { @include pre(2); }
Add columns of empty space as margin after an element.
// post(<$columns> [, <$context>, <$from>, <$style>])
.box { @include post(3); }
Shortcut to add empty space as margin before and after an element.
// squish([<$pre>, <$post>, <$context>, <$from>, <$style>])
.box { @include squish(2,3); }
Identical to pre.
// push(<$columns> [, <$context>, <$from>, <$style>])
.box { @include push(3); }
Add negative margins before an element, to pull it against the flow.
// pull(<$columns> [, <$context>, <$from>, <$style>])
.box { @include pull(2); }
Resets an element to default block behaviour.
// reset-columns([<$from>])
article { @include span-columns(6); } // articles are 6 cols wide
#news article { @include reset-columns; } // but news span the full width
// of their container
Apply to any previously-omega element to reset it’s float direction and margins to match non-omega grid elements. Note that unlike omega, this requires a context when nested.
// remove-omega([<$context>, <$from>, <$style>])
.gallery-image {
&:nth-child(3n) { @include remove-omega; } // 3rd images no longer complete rows.
}
Apply to any previously nth-omega element to reset it’s float direction and margins to match non-omega grid elements. Note that unlike omega, this requires a context when nested.
// remove-nth-omega([<$n>, <$selector>, <$context>, <$from>, <$style>])
.gallery-image {
@include remove-nth-omega(3n); // same as remove-omega example above.
}
Show the Susy Grid as a background-image on any container.
// susy-grid-background();
.page { @include susy-grid-background; }
Override the total width of your grid with an arbitrary length.
// $container-width: <length> | <boolean>;
$container-width: false;
Override the type of shell containing your grid.
// $container-style: <style>;
$container-style: magic;
The side of the Susy Grid from which the flow starts. For ltr documents, this is the left.
// $from-direction: <direction>;
$from-direction: left;
The direction that Omega elements should be floated.
// $omega-float: <direction>;
$omega-float: opposite-position($from-direction);
From the Compass Vertical Rhythm module, Susy uses your base font size to help manage em-based media-queries.
// $base-font-size: <px-size>;
$base-font-size: 16px;
Susy recognizes all the Compass Browser Support variables, although only IE6 and IE7 have special cases attached to them currently.
// $legacy-support-for-ie : <boolean>;
// $legacy-support-for-ie6 : <boolean>;
// $legacy-support-for-ie7 : <boolean>;
$legacy-support-for-ie : true;
$legacy-support-for-ie6 : $legacy-support-for-ie;
$legacy-support-for-ie7 : $legacy-support-for-ie;
If you are compiling seperate files for IE-fallbacks, it can be useful to output only the modern code in one file and only the fallbacks in another file. You can make at-breakpoint do exactly that by using the following settings.
Turn off media-query output for IE-only stylesheets.
// $breakpoint-media-output: <boolean>;
$breakpoint-media-output: true;
Turn off media-query fallback output for non-IE stylesheets.
// $breakpoint-ie-output: <boolean>;
$breakpoint-ie-output: true;
Pass through raw output without media-queries or fallback classes for IE-only stylesheets.
// $breakpoint-raw-output: <boolean>;
$breakpoint-raw-output: false;
Susy 2.x supports two syntax options, side by side. If you want to use the latest release but keep the old syntax, change your import from susy to susyone.
// With Susy 2.x installed...
@import "susyone";
If you ever want to upgrade to the new syntax, change the import back to susy, and follow these instructions:
In SusyOne, settings were handled as variables.
// the basics
$columns: 12;
$column-width: 4em;
$gutter-width: 1em;
$grid-padding: 1em;
// advanced
$container-width: false;
$container-style: magic;
$from-direction: left;
$omega-float: right;
// media-query fallbacks
$breakpoint-media-output: true;
$breakpoint-ie-output: true;
$breakpoint-raw-output: false;
All the media-query fallback settings have been dropped. Susy 2 no longer manages media-queries, but we play well with other media-query libraries, and include special Breakpoint integration. See their documentation for handling legacy browsers.
We’ve also dropped $grid-padding as a setting. If you want to add padding to your container, you can easily do it by hand.
The remaining settings can be easily mapped into the new syntax.
$susy: (
// the basics
columns: $total-columns,
gutters: $gutter-width / $column-width,
column-width: $column-width,
// advanced
container: $container-width,
math: if($container-style == magic, fluid, $container-style),
flow: if($from-direction == right, rtl, ltr),
last-flow: if($omega-float == $from-direction, from, to),
);
There are a few differences to note in the translation.
See 设置 for more details.
The columns and space functions from SusyOne have now been merged into the new span function.
// columns/space: <span> [, <context>, <math>]
$columns: columns(3, 6, static);
$space: space(2, 7, fluid);
// span
$span-columns: span(3 of 6 static);
$span-space: span(2 of 7 fluid wide);
The difference between columns and space in the old syntax is now covered by the narrow and wide spread keywords (with narrow being the default in most cases).
The gutter function remains, but the syntax has changed.
// gutter([<context>, <math>])
$old: gutter(6, static);
$new: gutter(6 static);
The container mixin remains, but media-query support has been removed. For now, at least, you’ll have to establish one container at a time inside media-query declarations.
In most (fluid/magic) cases, we set up the container for our largest layout, and let it flex fluidly from there. If you need to change explicit sizes at explicit breakpoints, we recommend using the container function to override only the width at different breakpoints.
// old
body {
@include container(4, 50em 8, 80em 12);
}
// new (simple)
body { @include container(12); }
// new (with breakpoint plugin)
body {
@include container(4);
@include breakpoint(50em) { max-width: container(8); }
@include breakpoint(80em) { max-width: container(12); }
}
The span-columns mixin has been renamed span, and has much more power and flexibility. The old $padding argument has been removed, but everything else tranlates cleanly. Note that $from took right or left as options, where the new flow setting takes rtl or ltr.
// span-columns(<$columns> [<omega> , <$context>, <$padding>, <$from>, <$style>])
.old { @include span-columns(3 omega, 12, $padding, left, static); }
.new { @include span(last 3 of 12 ltr static); }
The omega mixin still esists, and should work without any changes. For readability, omega can be replaced with last, but that’s up to you.
nth-omega has been deprecated, in favor of omega with nth-child selectors.
.old { @include nth-omega(last); }
.new:last-child { @include omega; }
Media-query support has been removed from the Susy core, because there are so many more powerful and flexible query-handling plugins. We recommend using Breakpoint, and we’ve written a translation of at-breakpoint (now called susy-breakpoint) that integrates smoothly with their controls.
.old {
@include at-breakpoint(30em 8 60em) {
// your 8-column media-query content...
}
}
.new {
@include susy-breakpoint(30em 60em, 8) {
// your 8-column media-query content...
}
}
This looks like a minor change, but it exposes a lot more power in both the media-queries and the changes to layout. See the Breakpoint docs for more detail on the former, and use our shorthand to control the latter in detail.
the layout and with-grid-settings mixins have merged to become with-layout. They continue to work much like before, with extra power exposed through the shorthand syntax.
// old
@include layout(12) { /* your 12-column layout */ }
@include with-grid-settings(8, 4em, 1em) { /* your custom layout */ }
// new
@include with-layout(12) { /* your 12-column layout... */ }
@include with-layout(8 (4em 1em)) { /* your custom layout */ }
There is still a mixin named layout, but it changes the global layout settings rather than wrapping a layout block.
// global layout
@include layout(12);
/* your 12-column layout... */
The set-container-width mixin can be replaced by applying the container function to the width or max-width of your containing element.
// old
.fluid { @include set-container-width(8, fluid); }
.static { @include set-container-width(12, static); }
// new
.fluid { max-width: container(8); }
.static { width: container(12); }
The setting has changed from the boolean $border-box-sizing to the new global-box-sizing, but the border-box-sizing mixin works exactly like before.
Isolation no longer requires it’s own mixin, as it can be controlled now through the span mixin for most cases. In those cases where you do still need a distinct mixin, isolate remains much like before.
.old { @include isolate(2, 12, left, static); }
.new { @include isolate(2 of 12 ltr static); }
the isolate-grid mixin has been renamed gallery, but is very similar in use.
.gallery-old { @include isolate-grid(3, 12, child, left, fluid); }
.gallery-new { @include gallery(3 of 12 left fluid, child); }
Only the selector argument remains split off from the others.
All the margin and padding mixins — pre, post, push, pull, prefix, suffix, pad, squish — remain unchanged, except that we now use the shorthand syntax in place of all the arguments.
See the new margins / padding documentation for details.
Susy is built in three distinct modules: math, output, and syntax. The math and output layers form the core of Susy — so abstract that they could be used for any grid system. That’s exactly what we hope will happen.
The syntax modules hold it all together. In the same way that you can theme a website, applying different CSS to the same markup, you can theme Susy by writing your own syntax (or extending one of ours).
We’ve written a powerful new Default Syntax, and we’re keeping the old Susy One available as well. But why stop there? You can create your own unique syntax, or port over the language of existing tools like oocss, singularity, zurb, neat, zen, blueprint, 960gs, etc., without ever leaving Susy.
While the Susy language module is built to support layouts of all kinds, we only need the math module for grid basics.
The Susy core has two settings: columns, and gutters.
$symmetrical: (
columns: 12,
gutters: 1/4,
);
$asymmetrical: (
columns: (1 3 4 6 2),
gutters: .5,
);
Both columns and gutters are set as unitless numbers, but you can think of them as “grid units” — as they are all relative to each other. 1/4 gutter is a quarter the size of 1 column.
Returns null if a grid is asymmetrical.
It’s not a difficult test, but it’s important to know what you’re dealing with.
// input
$sym: is-symmetrical(12);
$asym: is-symmetrical(2 4 6 3);
// output
$sym: 12;
$asym: null;
Find the number of columns in a given layout.
This is only necessary for asymmetrical grids, since symmetrical are already defined by their count, but the function handles both styles for the sake of flexibility.
<number>: Susy grid layouts are defined by columns. In a symmetrical grid all the columns are the same relative width, so they can be defined by the number of columns. We can have an “8-column” grid, or a “12-column” grid.
// input
$count: susy-count(12);
// output
$count: 12;
<list>: Asymmetrical grids are more complex. Since each column can have a different width relative to the other columns, we need to provide more detail about the columns. We can do that with a list of relative (unitless sizes). Each number in the list represents a number of grid units relative to the other numbers.
// input
$count: susy-count(1 2 4 3 1);
// output
$count: 5;
For asymmetrical grids, the number of columns is egual to the list length. This isn’t complex math.
Find the total sum of column-units in a layout.
Rather than counting how many columns there are, the susy-sum function calculates the total number of grid units covered. It’s a simple matter of adding together all the columns as well as the gutters between them.
// input
$susy-sum: susy-sum(7, .5);
// output: 7 + (6 * .5) = 10
$susy-sum: 10;
Most grids have one less gutter than column, but that’s not always true. The spread argument allows you to also include the gutters on either side. While the default narrow spread subtracts a gutter, the wide spread (common when using split gutters) has an equal number of columns and gutters.
// input
$wide-sum: susy-sum(7, .5, wide);
// output: 7 + (7 * .5) = 10.5
$wide-sum: 10.5;
On rare occasions you may actually want gutters on both sides, which we call a wider spread.
// input
$wider-sum: susy-sum(7, .5, wider);
// output: 7 + (8 * .5) = 11
$wider-sum: 11;
This is all possible with asymmetrical grids as well.
// input
$susy-sum: susy-sum(1 2 4 2, 1/3);
// output: (1 + 2 + 4 + 2) + (3 * 1/3) = 10
$susy-sum: 10;
Return a subset of columns at a given location.
This is only necessary for asymmetrical grids, since a symmetrical subset is always equal to the span, but the function handles both styles for the sake of flexibility.
The location is given as a column index, starting with 1, so that 1 is the first column, 2 is the second, and so on.
// input
$sym-span: susy-span(3, 2, 7);
$asym-span: susy-span(3, 2, (1 2 3 5 4));
// output: 3 columns, starting with the second
$sym-span: 3;
$asym-span: (2 3 5);
Find the sum of given slice.
This is where it all comes together. susy is the basic building-block for any grid system. It combines susy-span with susy-sum to return the unitless width of a given slice.
// input
$sym-span: susy(3, 2, 7, .5);
$asym-span: susy(3, 2, (1 2 3 5 4), .5);
// output
$sym-span: 4;
$asym-span: 11;
All you need to do is add units...
That’s really all it takes to build a grid system. The rest is just syntax. Start with susy().
$sum: susy(3, 2, 7);
If you want static grids, you can multiply the results by the width of one column.
// static
$column-width: 4em;
$static: $sum * $column-width;
For a fluid grid, divide the results by the context span sum, to get a percentage.
// fluid
$context: susy(7);
$fluid: percentage($sum / $context);
That’s all it takes. Now go build yourself a grid system!
BREAKING:
Backwards Incompatible:
Backwards Incompatible:
Susy 2.0 was re-written from the ground up.
This release is loaded with new features, but don’t let that fool you. Susy just became shockingly simple to use.
The gem name has changed from compass-susy-plugin to susy. First uninstall the old gem, then install the new one. If you have both gems installed, you will get errors.
Semantics:
We re-arranged the code in order to make the syntax simpler and more consistent:
We also removed several bothersome requirements:
Upgrade:
That’s all you need in order to upgrade from Susy 0.9.
You’re done! Stop worrying about all that “nested vs. root” bullshit, and start playing with the new toys!
If you use the $from directional arguments directly in the span-columns mixin, there may be one more change to make. See below:
New Features:
Everything here is about simplicity. Susy has scaled back to it’s most basic function: providing flexible grids. That is all.
Deprecated:
Removed:
New:
Deprecated:
Removed:
New Features:
Deprecated:
Other Changes:
Update: pre2 was missing a file in the manifest. Use pre4.
Update: Forgot to note one change: +susy is no longer assigned to the body tag, but instead at the top level of the document (not nested under anything).
Warning: This update is not backwards compatible. We’ve changed some things. You’ll have to change some things. Our changes were fairly major in cleaning up the code - yours will be minor and also clean up some code.
Added:
Removed:
Once you’ve upgraded, before you compile your files, make these changes:
Not a lot of new functionality here – it all moved over to Compass 0.10.0 – mostly just cleaning it up to match.
Not documented here. Check the commit log...
Author: | David Goodger |
---|---|
Contact: | docutils-develop@lists.sourceforge.net |
Revision: | $Revision: 7302 $ |
Date: | $Date: 2012-01-03 19:23:53 +0000 (Tue, 03 Jan 2012) $ |
Copyright: | This document has been placed in the public domain. |
This document describes standard definition files, such as sets of substitution definitions and interpreted text roles, that can be included in reStructuredText documents. The “include” directive has a special syntax for these standard definition files, angle brackets around the file name:
.. include:: <filename.txt>
The individual data files are stored with the Docutils source code in the “docutils” package, in the docutils/parsers/rst/include directory.
Many of the standard definition files contain sets of substitution definitions, which can be used in documents via substitution references. For example, the copyright symbol is defined in isonum.txt as “copy”:
.. include:: <isonum.txt>
Copyright |copy| 2003 by John Q. Public, all rights reserved.
Individual substitution definitions can also be copied from definition files and pasted into documents. This has two advantages: it removes dependencies, and it saves processing of unused definitions. However, multiple substitution definitions add clutter to the document.
Substitution references require separation from the surrounding text with whitespace or punctuation. To use a substitution without intervening whitespace, you can use the disappearing-whitespace escape sequence, backslash-space:
.. include:: isonum.txt
Copyright |copy| 2003, BogusMegaCorp\ |trade|.
Custom substitution definitions may use the “unicode” directive. Whitespace is ignored and removed, effectively sqeezing together the text:
.. |copy| unicode:: U+000A9 .. COPYRIGHT SIGN
.. |BogusMegaCorp (TM)| unicode:: BogusMegaCorp U+2122
.. with trademark sign
Copyright |copy| 2003, |BogusMegaCorp (TM)|.
In addition, the “ltrim”, “rtrim”, and “trim” options may be used with the “unicode” directive to automatically trim spaces from the left, right, or both sides (respectively) of substitution references:
.. |---| unicode:: U+02014 .. em dash
:trim:
The following files contain substitution definitions corresponding to XML character entity sets, from the following standards: ISO 8879 & ISO 9573-13 (combined), MathML, and XHTML1. They were generated by the tools/dev/unicode2rstsubs.py program from the input file unicode.xml, which is maintained as part of the MathML 2 Recommentation XML source.
Entity Set File | Description |
---|---|
isoamsa.txt | Added Mathematical Symbols: Arrows |
isoamsb.txt | Added Mathematical Symbols: Binary Operators |
isoamsc.txt | Added Mathematical Symbols: Delimiters |
isoamsn.txt | Added Mathematical Symbols: Negated Relations |
isoamso.txt | Added Mathematical Symbols: Ordinary |
isoamsr.txt | Added Mathematical Symbols: Relations |
isobox.txt | Box and Line Drawing |
isocyr1.txt | Russian Cyrillic |
isocyr2.txt | Non-Russian Cyrillic |
isodia.txt | Diacritical Marks |
isogrk1.txt | Greek Letters |
isogrk2.txt | Monotoniko Greek |
isogrk3.txt | Greek Symbols |
isogrk4.txt [1] | Alternative Greek Symbols |
isolat1.txt | Added Latin 1 |
isolat2.txt | Added Latin 2 |
isomfrk.txt [1] | Mathematical Fraktur |
isomopf.txt [1] | Mathematical Openface (Double-struck) |
isomscr.txt [1] | Mathematical Script |
isonum.txt | Numeric and Special Graphic |
isopub.txt | Publishing |
isotech.txt | General Technical |
mmlalias.txt | MathML aliases for entities from other sets |
mmlextra.txt [1] | Extra names added by MathML |
xhtml1-lat1.txt | XHTML Latin 1 |
xhtml1-special.txt | XHTML Special Characters |
xhtml1-symbol.txt | XHTML Mathematical, Greek and Symbolic Characters |
[1] | (1, 2, 3, 4, 5) There are *-wide.txt variants for each of these character entity set files, containing characters outside of the Unicode basic multilingual plane or BMP (wide-Unicode; code points greater than U+FFFF). Most pre-built Python distributions are “narrow” and do not support wide-Unicode characters. Python can be built with wide-Unicode support though; consult the Python build instructions for details. |
For example, the copyright symbol is defined as the XML character entity ©. The equivalent reStructuredText substitution reference (defined in both isonum.txt and xhtml1-lat1.txt) is |copy|.
The “s5defs.txt” standard definition file contains interpreted text roles (classes) and other definitions for documents destined to become S5/HTML slide shows.
下面是我们下一步的工作计划:
We’re always happy to hear your ideas as well. Leave us a note on GitHub Issues, or fork our code, and submit a pull request!
注解
This isn’t neverland, and Susy isn’t magic. We’re still talking about web design in a world where browsers disagree on implementation, standards are not always the standard, and your Sass code compiles into Boring Old CSS.
Don’t rely on Susy to solve all your problems — the table-saw can’t build your house for you. If you don’t understand what Susy is doing, take a look at the output CSS files, dig around, and find your own path. Nothing here is sacred, just a set of tools to help make your life easier.