These slides, references, and examples are on GitHub:
tsmith512.github.io/intro-to-singularity
tsmith512 on
Github,
Twitter,
LinkedIn,
Drupal.org,
Instagram, and
sometimes seen at Four Kitchens.
border-box
box sizing mode and do so
.push-3
, .col-md-6
, or .large-8
don’t mean anything; it’s litter.
Singularity is immensely flexible. There are things I cannot cover in one presentation, and I'm still exploring all the possibilities with this tool. Play with it, read the docs, experiment, and ask for help.
Singularity requires box-sizing: border-box;
// SCSS:
*, *:before, *:after {
@include box-sizing('border-box');
}
/* Compiled CSS */
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
Others Include: Bootstrap, Foundation, YUI Grids…
Twelve is a least common multiple for the number of columns you actually needed. How often did you actually use 12 even columns?
(If you did, have you considered Flexbox?)
Just another way to make columns and gutters.
But you can futz with ’em.
Image from Six Revisions: The 960 Grid System Made Easy.
You can build this in Singularity, if you want. (Don’t.)
@include add-grid(12);
@include add-gutter(1/3);
// ^^ Include once in a config partial or at the top of a Sass file above styles.
// THIS IS A GLOBAL CALL.
.container { @include clearfix; }
// ^^ Just clearfix your container, no need to add more grid calls
// Don't do this.
@include add-grid(10);
.container-A { @include add-grid(12); }
.container-B { @include add-grid(7); }
Replacing your global grid can cause maintainability issues because
the grid isn't scoped to that selector or Sass code block. If you do
need to do this, look at
the layout
mixin or overrides.
Include @include grid-span();
to put an element in a column.
@include add-grid(12); @include add-gutter(1/3);
.item { @include grid-span(1,1); }
.cyan { @include grid-span(1,1); } .magenta { @include grid-span(2,2); }
.yellow { @include grid-span(3,4); } .black { @include grid-span(4,7); }
.item { @include grid-span(1,1); }
.cyan { @include grid-span(1,1); } .magenta { @include grid-span(2,2); }
.yellow { @include grid-span(3,4); } .black { @include grid-span(4,7); }
Grid code added to CSS selector (class, element, nth-child, etc.) you're already using. → Lean Markup. Legible. Maintainable. Much easier in Drupal.
Couldn’t do tenths, sevenths, or fifths before, now could ya?
@include add-grid(X); // X equal columns
@include add-gutter(1/3); // Intercolumn space: 1/3 the width of one column.
Singularity has two basic ways
to specify the number of columns.
You’ve seen a single integer:
@include add-grid(4); // 4 equal columns
You can also write that this way:
@include add-grid(1 1 1 1); // 4 equal columns
And what might happen if we changed a 1 to 2?
I stuck to my comfy 12-column grid system without any issue. One day, I needed to change the width of a column. That sucked:
.every-single-element {
@include grid-span(X,Y); // Manual updates. Is this 6? 8? Or 4? Oops.
}
We use Sass because CTRL-F should not be a dev tool.
It’s not about first, second, ... twelfth column. It’s about:
They should. Those are words the designers are using.
// Not real code:
@include add-grid( LeftNav BodyArea RightRail );
// Real code:
@include add-grid( 2 4 1 );
// Another possibility:
@include add-grid( 2 4 300px ); // * See below.
* You could even use
Singularity Extras and the Calc output method
to specify that right rail in pixels, like ad dimensions.
Example on SassMeister.
She’s a Pit Boss in Vegas.
What could be more tabular and
grid-centric than a résumé?
So let’s build one.
@include add-grid(1 2 2 3 1);
@include add-gutter(1/4);
Duh.
@include grid-span(6, 7);
@include grid-span(12, 1);
width:100%;
)
Nope. (This is a Susy 1.x example.)
Desktop-only:
@include add-grid(1 2 2 3 1);
@include add-gutter(1/4);
Grids that grow and change:
@include add-grid(2);
@include add-grid(1 2 2 at 850px);
@include add-grid(1 2 2 3 1 at 1000px);
@include add-gutter(1/8);
@include add-gutter(1/4 at 850px);
@include add-grid(2);
@include add-grid(1 2 2 at 850px);
@include add-grid(1 2 2 3 1 at 1000px);
h2 {
text-align: center;
@include breakpoint(850px) { @include grid-span(1,1); text-align: right; }
@include breakpoint(1000px) { @include grid-span(1,1); /* * */ }
}
* It’s still (1,1), but it’s a new context.
Just having multiple grids defined isn’t enough.
You need to call @include grid-span()
inside a @include breakpoint()
to
trigger the new layout.
Example on SassMeister | Singularity’s Isolation output style (default) lets you do this.
Just change the add-grid()
arguments to re-order any
elements within a single row. Get clever with your
clear:x;
statements for even more flexibility.
Palantir's John Albin Wilkins explains this layout technique. Rounding inconsistencies could cause broken floated layouts. A negative right margin allows "each adjacent float to no longer sees the right edge of its siblings; it only sees the left inner edge of the container." Thanks, John!
Hint: watch the date (source-first) and the city (source-last).
Hint: watch the portrait.
At Four Kitchens, we use Aurora and Fences for leaner markup, then:
.views-row
as a grid item (great with :nth-child()
selectors).page.tpl.php
can be a container with block regions as a grid item.@include layout()
.
tsmith512 on
Github,
Twitter,
LinkedIn,
Drupal.org,
Instagram, and
sometimes seen at Four Kitchens.