XY Grid

A fully reworked new grid system in v6.4 which has all the variety inbuilt in the form of multiple grid types which includes margin grid, padding grid, frame grid, block grid and vertical grid.

XY Grid Basics

The XY grid works very similarly to the standard float grid, but includes a number of useful features only possible with Flexbox, like horizontal and vertical alignment, automatic sizing and a full vertical grid.


Browser support

The XY grid is supported in Chrome, Firefox, Safari 6+, IE11, iOS 7+, and Android 4.4+. Flexbox is supported in Android 2, but not reliably enough for use with this grid. (View Flexbox browser support.) We recommend only using the XY grid on projects that can live with purely cutting-edge browser support.


Importing

XY grid is the default Foundation grid. It is present by default in foundation.css of CDN link or package managers. In Sass, it will be generated by default by @include foundation-everything (unless $flex or $xy-grid are set to false).

If $xy-grid is set to false, the flex grid is used.
If $flex is set to false, the float grid is used instead.

You can manually generate the XY Grid with:

@import 'foundation';

@include foundation-xy-grid-classes(
  /* options
  $base-grid: true,
  $margin-grid: true,
  $padding-grid: true,
  $block-grid: true,
  $collapse: true,
  $offset: true,
  $vertical-grid: true,
  $frame-grid: true
  */
);

Basics

The structure of XY grid uses .grid-x, .grid-y, and .cell as its base. Without defining a gutter type the cells will simply split up the space without any gutters.

Watch this part in video

edit on codepen button
<div class="grid-x">
  <div class="cell">full width cell</div>
  <div class="cell">full width cell</div>
</div>
<div class="grid-x">
  <div class="cell small-6">6 cells</div>
  <div class="cell small-6">6 cells</div>
</div>
<div class="grid-x">
  <div class="cell medium-6 large-4">12/6/4 cells</div>
  <div class="cell medium-6 large-8">12/6/8 cells</div>
</div>
full width cell
full width cell
6 cells
6 cells
12/6/4 cells
12/6/8 cells

Gutters

The defining feature of the XY grid is the ability to use margin AND padding grids in harmony. To define a grid type, simply set .grid-margin-x/.grid-margin-y or .grid-padding-x/.grid-padding-y on the grid.

Watch this part in video

edit on codepen button
<div class="grid-x grid-margin-x">
  <div class="cell medium-6 large-4">12/6/4 cells</div>
  <div class="cell medium-6 large-8">12/6/8 cells</div>
</div>
<div class="grid-x grid-padding-x">
  <div class="cell medium-6 large-4">12/6/4 cells</div>
  <div class="cell medium-6 large-8">12/6/8 cells</div>
</div>
12/6/4 cells
12/6/8 cells
12/6/4 cells
12/6/8 cells

Grid Container

The grid defaults to the full width of the available space. To contain it horizontally use the grid-container class. The container will be centered and have a max-width equal to your $grid-container setting (1200px by default), along with padding on the left/right equal to half your $grid-container-padding setting.

<div class="grid-container">
  <div class="grid-x grid-margin-x">
    <div class="cell small-4">cell</div>
    <div class="cell small-4">cell</div>
    <div class="cell small-4">cell</div>
  </div>
</div>

Grid Container Fluid

To stretch the content to the full width of the available space, simply add the class fluid to your grid-container.

<div class="grid-container fluid">
  <div class="grid-x grid-margin-x">
    <div class="cell small-4">cell</div>
    <div class="cell small-4">cell</div>
    <div class="cell small-4">cell</div>
  </div>
</div>

Grid Container Full

To stretch the content to the full width of the available space and remove grid container padding, simply add the class full to your grid-container. Note that this variation is primarily for use for the grid-margin-x - it works with grid-padding-x too, but will work the same as .grid-container.fluid.

Please note that when you are using `grid-margin-x` on a `grid-container` with `full` class you will also need to hide the horizontal overflow in order for this to work correctly if your content is going to touch the sides of the viewport.

The best way to do this is:  `body {overflow-x: hidden;}`

<div class="grid-container full">
  <div class="grid-x grid-margin-x">
    <div class="cell small-4">cell</div>
    <div class="cell small-4">cell</div>
    <div class="cell small-4">cell</div>
  </div>
</div>

Auto Sizing

If the class .auto or .[size]-auto is added to the cell, it will take up the remaining space.

<div class="grid-x grid-margin-x">
  <div class="cell small-4">4 cells</div>
  <div class="cell auto">Whatever's left!</div>
</div>
4 cells
Whatever's left!

Multiple expanding cells will share the leftover space equally.

<div class="grid-x grid-margin-x">
  <div class="cell small-4">4 cells</div>
  <div class="cell auto">Whatever's left!</div>
  <div class="cell auto">Whatever's left!</div>
</div>
4 cells
Whatever's left!
Whatever's left!

A cell can also be made to shrink, by adding the .shrink or .[size]-shrink class. This means it will only take up the space its contents need.

<div class="grid-x grid-margin-x">
  <div class="cell shrink">Shrink!</div>
  <div class="cell auto">Expand!</div>
</div>
Shrink!
Expand!

Responsive Adjustments

To switch back to the auto behavior from a percentage or shrink behavior, use the classes .[size]-auto or .[size]-shrink. In the below example, the cells stack on small screens, and become even-width on large screens.

<div class="grid-x">
  <div class="cell large-auto">One</div>
  <div class="cell large-auto">Two</div>
  <div class="cell large-auto">Three</div>
  <div class="cell large-auto">Four</div>
  <div class="cell large-auto">Five</div>
  <div class="cell large-auto">Six</div>
</div>
One
Two
Three
Four
Five
Six

Collapse Cells X Grid only

The .[size]-[gutter-type]-collapse class lets you remove cell gutters.

There are times when you won't want each media query to be collapsed. In this case, use the media query size you want and collapse and add that to your grid element. Example shows gutters at small and no gutters on medium and up.

<div class="grid-x grid-margin-x medium-margin-collapse">
  <div class="cell small-6">
    Gutters at small no gutters at medium.
  </div>
  <div class="cell small-6">
    Gutters at small no gutters at medium.
  </div>
</div>
Gutters at small no gutters at medium.
Gutters at small no gutters at medium.

Offsets X Grid only

Offsets work by applying margin-left to a grid.

<div class="grid-x grid-margin-x">
  <div class="cell small-4 large-offset-2">Offset 2 on large</div>
  <div class="cell small-4">4 cells</div>
</div>
Offset 2 on large
4 cells

Block Grids X Grid only

To define cell widths within a direction-level, instead of the individual cell level, add the class .[size]-up-[n] to a grid-x, where [n] is the number of cells to display per direction, and [size] is the breakpoint at which to apply the effect.

This example uses padding grid but this can be used with margin grid too.
edit on codepen button
<div class="grid-x grid-padding-x small-up-2 medium-up-4 large-up-6">
  <div class="cell">cell</div>
  <div class="cell">cell</div>
  <div class="cell">cell</div>
  <div class="cell">cell</div>
  <div class="cell">cell</div>
  <div class="cell">cell</div>
</div>
cell
cell
cell
cell
cell
cell

Block Grids are not available for the vertical grids. Use the basic layout with a size applied on each cell of the grid instead.


Looking for Push/Pull?

Push and pull are a bit of a hack solution and was only necessary for Float based grids. But for flexbox, this hack is not needed as source ordering does this with ease.


Vertical Grids

The XY grid also supports vertical grids. Simply apply .grid-y instead of .grid-x. The internal cells will shift automatically to provide spacing vertically rather than horizontally.

You can also apply margin or padding with .grid-margin-y and .grid-padding-y to apply spacing to the top and bottom of cells.

Watch this part in video

Please note for vertical grids to work, the grid needs a height. You can also use [grid frame](#grid-frame) to create a 100% viewport height vertical grid (or height:100%; if nested).

edit on codepen button
<div class="grid-y" style="height: 500px;">
  <div class="cell small-6 medium-8 large-2">
    6/8/2
  </div>
  <div class="cell small-6 medium-4 large-10">
    6/4/10
  </div>
</div>
6/8/2
6/4/10

Grid Frame

The XY grid incorporates the grid frame from Foundation for Apps plus many other useful features. To start, add .grid-frame to the grid. This sets the grid to be 100vh (the full height of the browser window).

Please note that to use `.grid-margin-x` or `.grid-margin-y` with `.grid-frame` you need to hide the overflow on the body like so: `body {overflow: hidden;}`. However, take care not to unintentionally hide overflow body content on small screens when using `.medium-grid-frame`.

Here's an example of what you can do:

Watch this part in video

edit on codepen button
<div class="grid-y medium-grid-frame">
  <div class="cell shrink header medium-cell-block-container">
    <h1>Grid Frame Header</h1>
    <div class="grid-x grid-padding-x">
      <div class="cell medium-4">
        A medium 4 cell
      </div>
      <div class="cell medium-4 medium-cell-block">
        <p style="width:80vw;">A medium 4 cell block... on medium this content should overflow and let you horizontally scroll across... one might use this for an array of options</p>
      </div>
      <div class="cell medium-4">
        A medium 4 cell
      </div>
    </div>
  </div>
  <div class="cell medium-auto medium-cell-block-container">
    <div class="grid-x grid-padding-x">
      <div class="cell medium-4 medium-cell-block-y">
        <h2>Independent scrolling sidebar</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer lacus odio, accumsan id ullamcorper eget, varius nec erat. Nulla facilisi. Donec dui felis, euismod nec finibus vitae, dapibus quis arcu. Maecenas tempor et ipsum quis venenatis. Ut posuere sed augue sit amet efficitur. Sed imperdiet, justo id tempus rhoncus, est est viverra turpis, non vulputate magna lectus et nisl. Pellentesque ultrices porttitor vehicula. Ut aliquet efficitur ligula, a consectetur felis. Proin tristique ut augue nec luctus. Curabitur a sapien pretium, auctor elit a, efficitur erat. Donec tincidunt dui vel velit bibendum euismod. Cras vitae nibh dui. Aliquam erat volutpat. Etiam sit amet arcu a erat efficitur facilisis. Ut viverra dapibus turpis, et ornare justo. Integer in dui cursus, dignissim tortor a, hendrerit risus.</p>

        <p>Suspendisse pulvinar, massa iaculis feugiat lobortis, dolor sapien vestibulum nulla, vel cursus tellus leo in lorem. Aliquam eu placerat urna. Suspendisse sed viverra orci, ut mattis neque. Fusce non ultrices nisi. In sagittis varius mollis. Quisque dolor quam, consectetur eu lacinia ac, ullamcorper vel arcu. Nullam mattis imperdiet nulla sed ornare. Praesent tristique, est id eleifend vestibulum, neque nibh condimentum ex, nec lobortis purus justo a libero. Phasellus id ex ac nunc hendrerit hendrerit. Nullam urna ipsum, rutrum at fringilla vel, venenatis non purus. Maecenas egestas ex vitae venenatis molestie. Ut et odio egestas, accumsan neque et, viverra nisl. Sed faucibus nec nulla sed imperdiet. Fusce quis sem ac urna semper tempor a id elit. Nulla fringilla vitae sapien a vehicula.</p>

      </div>
      <div class="cell medium-8 medium-cell-block-y">
        <h2>Independent scrolling body</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer lacus odio, accumsan id ullamcorper eget, varius nec erat. Nulla facilisi. Donec dui felis, euismod nec finibus vitae, dapibus quis arcu. Maecenas tempor et ipsum quis venenatis. Ut posuere sed augue sit amet efficitur. Sed imperdiet, justo id tempus rhoncus, est est viverra turpis, non vulputate magna lectus et nisl. Pellentesque ultrices porttitor vehicula. Ut aliquet efficitur ligula, a consectetur felis. Proin tristique ut augue nec luctus. Curabitur a sapien pretium, auctor elit a, efficitur erat. Donec tincidunt dui vel velit bibendum euismod. Cras vitae nibh dui. Aliquam erat volutpat. Etiam sit amet arcu a erat efficitur facilisis. Ut viverra dapibus turpis, et ornare justo. Integer in dui cursus, dignissim tortor a, hendrerit risus.</p>
        <p>Suspendisse pulvinar, massa iaculis feugiat lobortis, dolor sapien vestibulum nulla, vel cursus tellus leo in lorem. Aliquam eu placerat urna. Suspendisse sed viverra orci, ut mattis neque. Fusce non ultrices nisi. In sagittis varius mollis. Quisque dolor quam, consectetur eu lacinia ac, ullamcorper vel arcu. Nullam mattis imperdiet nulla sed ornare. Praesent tristique, est id eleifend vestibulum, neque nibh condimentum ex, nec lobortis purus justo a libero. Phasellus id ex ac nunc hendrerit hendrerit. Nullam urna ipsum, rutrum at fringilla vel, venenatis non purus. Maecenas egestas ex vitae venenatis molestie. Ut et odio egestas, accumsan neque et, viverra nisl. Sed faucibus nec nulla sed imperdiet. Fusce quis sem ac urna semper tempor a id elit. Nulla fringilla vitae sapien a vehicula.</p>
        <p>Nullam vestibulum lorem nec lectus egestas, nec ullamcorper diam maximus. Maecenas condimentum, nibh at blandit semper, ex erat tempus magna, id maximus neque velit accumsan nibh. Aenean dignissim lorem eu nisl laoreet vestibulum. Vivamus efficitur et augue vitae tincidunt. Etiam et magna felis. Integer mattis, nisi aliquet scelerisque blandit, ex mi sodales ante, eget accumsan quam magna et ligula. Curabitur id tristique leo. Proin rutrum mi vitae enim rhoncus, at cursus neque eleifend. Integer ultrices volutpat tellus ac porta. Fusce sollicitudin venenatis lacinia. Fusce ante lorem, gravida semper varius non, pharetra non erat. Sed dapibus arcu turpis, ac sollicitudin nibh lacinia vel. Nullam at enim porta, luctus metus sit amet, rutrum odio. Cras tempor enim vel pellentesque sollicitudin. Maecenas ullamcorper, sem non accumsan volutpat, neque tortor pulvinar orci, ut ultrices ligula lorem ut risus.</p>
        <p>Aliquam facilisis, nibh eget posuere suscipit, arcu sapien iaculis odio, in molestie dolor lectus vitae sem. Cras id nunc mollis mi rutrum dapibus. Quisque rutrum a augue at scelerisque. Praesent faucibus ac enim vitae gravida. Sed et sodales elit. Duis magna lectus, interdum sit amet metus a, sagittis varius magna. Proin nibh lectus, egestas a luctus ut, dapibus et enim. Curabitur fringilla ipsum vitae nunc imperdiet consectetur eget non neque. Suspendisse ultricies odio quis lorem vulputate, ac vulputate turpis feugiat. Maecenas posuere rhoncus orci, in ornare velit suscipit tempor. Curabitur pretium nisl id lorem placerat consequat. In quis quam eros. Nam mattis elit eu quam sagittis, in varius erat tempor.</p>
        <p>Fusce felis magna, pellentesque eget mollis a, rutrum id eros. Curabitur auctor varius arcu a consequat. Phasellus quis pulvinar enim, eu ultricies justo. Pellentesque risus libero, dapibus at erat ultricies, gravida varius erat. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nulla tempus, justo ut laoreet mollis, nunc tellus convallis urna, vel pretium dui velit eget ligula. Aliquam semper sed nulla a molestie. Maecenas at egestas massa, vitae aliquam mi. Fusce nec sem egestas, pretium lacus non, tincidunt sapien. Sed tristique odio at ultricies vulputate. Integer et convallis augue, eu aliquam enim. Mauris ut faucibus diam. Donec vulputate nunc sed congue accumsan. Etiam lobortis nisi quis lacinia pharetra.</p>
      </div>
    </div>
  </div>
  <div class="cell shrink footer">
    <h3>Here's my footer</h3>
  </div>
</div>

Grid Frame Header

A medium 4 cell

A medium 4 cell block... on medium this content should overflow and let you horizontally scroll across... one might use this for an array of options

A medium 4 cell

Independent scrolling sidebar

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer lacus odio, accumsan id ullamcorper eget, varius nec erat. Nulla facilisi. Donec dui felis, euismod nec finibus vitae, dapibus quis arcu. Maecenas tempor et ipsum quis venenatis. Ut posuere sed augue sit amet efficitur. Sed imperdiet, justo id tempus rhoncus, est est viverra turpis, non vulputate magna lectus et nisl. Pellentesque ultrices porttitor vehicula. Ut aliquet efficitur ligula, a consectetur felis. Proin tristique ut augue nec luctus. Curabitur a sapien pretium, auctor elit a, efficitur erat. Donec tincidunt dui vel velit bibendum euismod. Cras vitae nibh dui. Aliquam erat volutpat. Etiam sit amet arcu a erat efficitur facilisis. Ut viverra dapibus turpis, et ornare justo. Integer in dui cursus, dignissim tortor a, hendrerit risus.

Suspendisse pulvinar, massa iaculis feugiat lobortis, dolor sapien vestibulum nulla, vel cursus tellus leo in lorem. Aliquam eu placerat urna. Suspendisse sed viverra orci, ut mattis neque. Fusce non ultrices nisi. In sagittis varius mollis. Quisque dolor quam, consectetur eu lacinia ac, ullamcorper vel arcu. Nullam mattis imperdiet nulla sed ornare. Praesent tristique, est id eleifend vestibulum, neque nibh condimentum ex, nec lobortis purus justo a libero. Phasellus id ex ac nunc hendrerit hendrerit. Nullam urna ipsum, rutrum at fringilla vel, venenatis non purus. Maecenas egestas ex vitae venenatis molestie. Ut et odio egestas, accumsan neque et, viverra nisl. Sed faucibus nec nulla sed imperdiet. Fusce quis sem ac urna semper tempor a id elit. Nulla fringilla vitae sapien a vehicula.

Independent scrolling body

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer lacus odio, accumsan id ullamcorper eget, varius nec erat. Nulla facilisi. Donec dui felis, euismod nec finibus vitae, dapibus quis arcu. Maecenas tempor et ipsum quis venenatis. Ut posuere sed augue sit amet efficitur. Sed imperdiet, justo id tempus rhoncus, est est viverra turpis, non vulputate magna lectus et nisl. Pellentesque ultrices porttitor vehicula. Ut aliquet efficitur ligula, a consectetur felis. Proin tristique ut augue nec luctus. Curabitur a sapien pretium, auctor elit a, efficitur erat. Donec tincidunt dui vel velit bibendum euismod. Cras vitae nibh dui. Aliquam erat volutpat. Etiam sit amet arcu a erat efficitur facilisis. Ut viverra dapibus turpis, et ornare justo. Integer in dui cursus, dignissim tortor a, hendrerit risus.

Suspendisse pulvinar, massa iaculis feugiat lobortis, dolor sapien vestibulum nulla, vel cursus tellus leo in lorem. Aliquam eu placerat urna. Suspendisse sed viverra orci, ut mattis neque. Fusce non ultrices nisi. In sagittis varius mollis. Quisque dolor quam, consectetur eu lacinia ac, ullamcorper vel arcu. Nullam mattis imperdiet nulla sed ornare. Praesent tristique, est id eleifend vestibulum, neque nibh condimentum ex, nec lobortis purus justo a libero. Phasellus id ex ac nunc hendrerit hendrerit. Nullam urna ipsum, rutrum at fringilla vel, venenatis non purus. Maecenas egestas ex vitae venenatis molestie. Ut et odio egestas, accumsan neque et, viverra nisl. Sed faucibus nec nulla sed imperdiet. Fusce quis sem ac urna semper tempor a id elit. Nulla fringilla vitae sapien a vehicula.

Nullam vestibulum lorem nec lectus egestas, nec ullamcorper diam maximus. Maecenas condimentum, nibh at blandit semper, ex erat tempus magna, id maximus neque velit accumsan nibh. Aenean dignissim lorem eu nisl laoreet vestibulum. Vivamus efficitur et augue vitae tincidunt. Etiam et magna felis. Integer mattis, nisi aliquet scelerisque blandit, ex mi sodales ante, eget accumsan quam magna et ligula. Curabitur id tristique leo. Proin rutrum mi vitae enim rhoncus, at cursus neque eleifend. Integer ultrices volutpat tellus ac porta. Fusce sollicitudin venenatis lacinia. Fusce ante lorem, gravida semper varius non, pharetra non erat. Sed dapibus arcu turpis, ac sollicitudin nibh lacinia vel. Nullam at enim porta, luctus metus sit amet, rutrum odio. Cras tempor enim vel pellentesque sollicitudin. Maecenas ullamcorper, sem non accumsan volutpat, neque tortor pulvinar orci, ut ultrices ligula lorem ut risus.

Aliquam facilisis, nibh eget posuere suscipit, arcu sapien iaculis odio, in molestie dolor lectus vitae sem. Cras id nunc mollis mi rutrum dapibus. Quisque rutrum a augue at scelerisque. Praesent faucibus ac enim vitae gravida. Sed et sodales elit. Duis magna lectus, interdum sit amet metus a, sagittis varius magna. Proin nibh lectus, egestas a luctus ut, dapibus et enim. Curabitur fringilla ipsum vitae nunc imperdiet consectetur eget non neque. Suspendisse ultricies odio quis lorem vulputate, ac vulputate turpis feugiat. Maecenas posuere rhoncus orci, in ornare velit suscipit tempor. Curabitur pretium nisl id lorem placerat consequat. In quis quam eros. Nam mattis elit eu quam sagittis, in varius erat tempor.

Fusce felis magna, pellentesque eget mollis a, rutrum id eros. Curabitur auctor varius arcu a consequat. Phasellus quis pulvinar enim, eu ultricies justo. Pellentesque risus libero, dapibus at erat ultricies, gravida varius erat. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nulla tempus, justo ut laoreet mollis, nunc tellus convallis urna, vel pretium dui velit eget ligula. Aliquam semper sed nulla a molestie. Maecenas at egestas massa, vitae aliquam mi. Fusce nec sem egestas, pretium lacus non, tincidunt sapien. Sed tristique odio at ultricies vulputate. Integer et convallis augue, eu aliquam enim. Mauris ut faucibus diam. Donec vulputate nunc sed congue accumsan. Etiam lobortis nisi quis lacinia pharetra.


Building Semantically

XY grid CSS is generated with a powerful set of Sass mixins, which you can use in your own code to build a semantic grid.

Grid Container

Use the xy-grid-container() mixin to create a grid container. This contains the grid to the width specified in $grid-container.

.container {
  @include xy-grid-container;
}

Grids

Use the xy-grid() mixin to create a grid.

.my-grid {
  @include xy-grid;
}

Gutters

Use the xy-gutters() mixin to add gutters to an item. The xy-cell mixin used this to output gutters, but you can use this to add responsive gutters to anything you like. This is especially powerful as you can specify where you want the gutters, like so:

.gallery-item {
  @include xy-gutters($gutter-position: left right bottom);
}

Cells

Use the xy-cell() mixin to create a cell. There are a number of ways to define the size of a cell. xy-cell accepts a few different keywords as well as specific sizes: full (full width), auto (automatic width) and shrink (take up only the space it needs) or any fraction (6, 50%, 1 of 2 or 1/2...).

.main-content {
  // Use the full column count (100%)
  @include xy-cell();

  // Use a column count (33%);
  @include xy-cell(4);

  // Use a percentage (15%)
  @include xy-cell(15%);

  // Use a custom fraction (20%)
  @include xy-cell(1 of 5);
}

The cell size calculator can also be accessed as a function. This gives you the percentage value, without any of the grid cell CSS.

.main-content {
  width: xy-cell-size(1 of 7);
}

A cell is composed of 3 parts: the base, the size and the gutters. In order to avoid duplicating properties, you can choose the parts to generate with the $output option, or call the XY cell mixins dedicated to each part individually.

.my-cell {
  @include xy-cell(12, $gutters: none);
}
.my-cell.half-size {
  @include xy-cell(6, $gutters: none, $output: (size));
  // Or @include xy-cell-size(6);
}
XY cell with margin gutters (by default) has gutters defined within their width/height. For this reason, you need to generate the gutter part of cells with margin gutters even when you only want to change the size.

Refer to the Sass documentation of the xy-cell mixin for the full list of arguments. See also xy-cell-base, xy-cell-size and xy-cellgutters.


Responsive Grids

Pair xy-cell with the breakpoint() mixin to make your grid responsive. The xy-grid mixin will automatically detect the breakpoint in which it is, but you can force it with the $breakpoint option. Refer to the Sass documentation below to learn how each mixin works and the available arguments.

.my-cell-medium-only-8 {
  @include xy-cell();

  // Generate a cell with a 8/12 width on medium breakpoint only
  @include breakpoint(medium) {
    @include xy-cell(8);
  }
}

You can also use for more advanced responsive cells:

  // ... with a 8/12 width on medium breakpoint and above (with the medium gutters)
  @include breakpoint(medium up) {
    @include xy-cell(8);
  }
  // ... with a 8/12 width on medium, large and xlarge (with the corresponding gutters)
  @include breakpoint(medium, large, xlarge up) {
    @include xy-cell(8);
  }
If you pass multiple breakpoints to the breakpoint mixin, it will duplicate its content for each of them. Be careful to only use breakpoint with properties that should change across breakpoints.

Custom Block Grid

Use the xy-grid-layout() mixin to create your own block grid. By default the mixin takes 2 parameters:

  • number of columns
  • child selector

Refer to the Sass documentation below for the full list of arguments.

Here's an example:

.gallery {
  @include xy-grid;
  @include xy-grid-layout(3, '.gallery-item');
}

That outputs this CSS:

.gallery > .gallery-item {
  width: calc(33.33333% - 1.25rem);
  margin-right: 0.625rem;
  margin-left: 0.625rem;
}

Sass Reference

Variables

The default styles of this component can be customized using these Sass variables in your project's settings file.

NameTypeDefault ValueDescription
$xy-grid Boolean true

Enables the XY grid.

$grid-container Number $global-width

The maximum width of a grid container.

$grid-columns Number 12

The number of columns used in the grid.

$grid-margin-gutters Map or Length "small": 20px
"medium": 30px

The amount of margin between cells at different screen sizes when using the margin grid. To use just one size, set the variable to a number instead of a map.

$grid-padding-gutters Map or Length $grid-margin-gutters

The amount of padding in cells at different screen sizes when using the padding grid. To use just one size, set the variable to a number instead of a map.

$grid-container-padding Map or Length $grid-padding-gutters

The amount of padding to use when padding the grid-container.

$grid-container-max Number $global-width

The maximum width to apply to a grid container

$xy-block-grid-max Number 8

The maximum number of cells in an XY block grid.


Mixins

We use these mixins to build the final CSS output of this component. You can use the mixins yourself to build your own class structure out of our components.

xy-grid-frame

@include xy-grid-frame($vertical, $nested, $gutters, $breakpoint, $include-base);

Modifies a grid to give it "frame" behavior (no overflow, no wrap, stretch behavior)

ParameterTypeDefault ValueDescription
$vertical Boolean false

Is grid vertical or horizontal. Should match grid.

$nested Boolean false

Is grid nested or not. If nested is true this sets the frame to 100% height, otherwise will be 100vh.

$gutters Number or Map null

Map or single value for gutters.

$breakpoint String null

The name of the breakpoint size in your gutters map to get the size from.

$include-base Boolean true

Include the base styles that don't vary per breakpoint.


xy-cell-block

@include xy-cell-block($vertical);

Modifies a cell to give it "block" behavior (overflow auto, inertial scrolling)

ParameterTypeDefault ValueDescription
$vertical Boolean false

Is grid vertical or horizontal. Should match grid.


xy-cell-block-container

@include xy-cell-block-container;

Container for inside a grid frame containing multiple blocks. Typically used as a modifier for a .cell to allow the cell to pass along flex sizing constraints / from parents to children.


xy-cell-base

@include xy-cell-base($size);

Sets base flex properties for cells.

ParameterTypeDefault ValueDescription
$size Keyword full

The size of your cell. Accepts full, auto, shrink, grow, or any other value representing a cell size (it will be treated as shrink).


xy-cell-reset

@include xy-cell-reset($vertical);

Resets a cells width (or height if vertical is true) as well as strips its gutters.

ParameterTypeDefault ValueDescription
$vertical Boolean false

Set to true to output vertical (height) styles rather than widths.


xy-cell-size

@include xy-cell-size($size, $gutters, $gutter-type, $breakpoint, $vertical);

Sets sizing properties for cells.

Gutters-related arguments are required for cells with margin gutters (by default) as the gutter is included in the width.

ParameterTypeDefault ValueDescription
$size Keyword or Number full

The size of your cell. Can be full (100% width), auto (use all available space), shrink (use only the required space) or any fraction (6, 50%, 1 of 2 or 1/2...).

$gutters Number or Map $grid-margin-gutters

Map or single value for gutters.

$gutter-type Keyword margin

Type of gutter to output. Accepts margin, padding or none.

$breakpoint String null

The name of the breakpoint size in your gutters map to get the size from. If auto, generates sizes adapted for responsive gutters. If using with the breakpoint() mixin this will be set automatically unless manually entered.

$vertical Boolean false

Set to true to output vertical (height) styles rather than widths.


xy-cell-gutters

@include xy-cell-gutters($gutters, $gutter-type, $gutter-position, $breakpoint, $vertical);

Sets gutters properties for cells.

ParameterTypeDefault ValueDescription
$gutters Number or Map $grid-margin-gutters

Map or single value for gutters.

$gutter-type Keyword margin

Type of gutter to output. Accepts margin, padding or none.

$gutter-position List null

The position to apply gutters to. Accepts top, bottom, left, right in any combination. By default right left for horizontal cells and top bottom for vertical cells.

$breakpoint String null

The name of the breakpoint size in your gutters map to get the size from. If auto, generates responsive gutters. If using with the breakpoint() mixin this will be set automatically unless manually entered.

$vertical Boolean false

Direction of the gutters to output. See $gutter-position.


xy-cell

@include xy-cell($size, $gutter-output, $gutters, $gutter-type, $gutter-position, $breakpoint, $vertical, $output);

Creates a cell for your grid.

ParameterTypeDefault ValueDescription
$size Keyword or Number full

The size of your cell. Can be full (100% width), auto (use all available space), shrink (use only the required space) or any fraction (6, 50%, 1 of 2 or 1/2...).

$gutter-output Boolean null

[DEPRECATED] Whether or not to output gutters.

$gutters Number or Map $grid-margin-gutters

Map or single value for gutters.

$gutter-type Keyword margin

Type of gutter to output. Accepts margin, padding or none.

$gutter-position List null

The position to apply gutters to. Accepts top, bottom, left, right in any combination. By default right left for horizontal cells and top bottom for vertical cells.

$breakpoint String null

The name of the breakpoint size in your gutters map to get the size from. If auto, generates responsive gutters. If using with the breakpoint() mixin this will be set automatically unless manually entered.

$vertical Boolean false

Set to true to output vertical (height) styles rather than widths.

$output List base size gutters

Cell parts to output. You will need to generate others parts of the cell seperately, it may not work properly otherwise.


xy-cell-static

Deprecated in v6.6.0

@include xy-cell-static($size, $gutter-output, $gutters, $gutter-type, $breakpoint, $vertical);

Creates a single breakpoint sized grid. Used to generate our grid classes.

xy-cell-static() is deprecated and will be removed. Use xy-cell() instead with $output: (size gutters) to not generate the cell base. See migration notes at https://git.io/foundation-6-6-0

ParameterTypeDefault ValueDescription
$size Keyword or Number full

The size of your cell. Can be full (100% width), auto (use all available space), shrink (use only the required space) or any fraction (6, 50%, 1 of 2 or 1/2...).

$gutter-output Boolean true

Whether or not to output gutters. Always true for margin gutters.

$gutters Number or Map $grid-margin-gutters

Map or single value for gutters.

$gutter-type Keyword margin

Map or single value for gutters.

$breakpoint String null

The name of the breakpoint size in your gutters map to get the size from. If using with the breakpoint() mixin this will be set automatically unless manually entered.

$vertical Boolean false

Set to true to output vertical (height) styles rather than widths.


xy-grid-collapse

@include xy-grid-collapse($selector, $gutter-type, $gutter-position, $min-breakpoint);

Collapses the grid a cells within it.

ParameterTypeDefault ValueDescription
$selector String .cell

The child element to remove the gutter from.

$gutter-type Keyword margin

The type of gutter to remove.

$gutter-position List right left

The positions to remove gutters from. Accepts top, bottom, left, right in any combination.

$min-breakpoint Keyword $-zf-zero-breakpoint

Minimum breakpoint in $breakpoint-classes for which to collapse the gutter.


xy-grid-container

@include xy-grid-container($width, $padding);

Creates a max width container, designed to house your grid content.

ParameterTypeDefault ValueDescription
$width Number $grid-container

a width to limit the container to.

$padding Number $grid-container-padding

paddings of the container.


xy-grid

@include xy-grid($direction, $wrap);

Creates a container for your flex cells.

ParameterTypeDefault ValueDescription
$direction Keyword horizontal

Either horizontal or vertical direction of cells within.

$wrap Boolean true

If the cells within should wrap or not.


xy-gutters

@include xy-gutters($gutters, $gutter-type, $gutter-position, $negative);

Create gutters for a cell/container.

ParameterTypeDefault ValueDescription
$gutters Number or Map $grid-margin-gutters

Map or single value for gutters.

$gutter-type Keyword margin

Type of gutter to output. Accepts either margin or padding.

$gutter-position List right left

The position to apply gutters to. Accepts top, bottom, left, right in any combination.

$negative Boolean false

Whether to apply the gutter as a negative value. Commonly used for nested grids.


xy-grid-layout

@include xy-grid-layout($n, $selector, $gutter-output, $gutters, $gutter-type, $gutter-position, $breakpoint, $vertical, $output);

Sizes child elements so that $n number of items appear on each row.

ParameterTypeDefault ValueDescription
$n Number None

Number of elements to display per row.

$selector String '.cell'

Selector(s) to use for child elements.

$gutter-output Boolean null

[DEPRECATED] Whether or not to output gutters.

$gutters Number or Map $grid-margin-gutters

Map or single value for gutters.

$gutter-type Keyword margin

Type of gutter to output. Accepts margin, padding or none.

$gutter-position List null

The position to apply gutters to. Accepts top, bottom, left, right in any combination. By default right left for horizontal cells and top bottom for vertical cells.

$breakpoint String null

The breakpoint to use for the cell generation. If using with the breakpoint() mixin this will be set automatically unless manually entered.

$vertical Boolean false

Set to true to output vertical (height) styles rather than widths.

$output List base size gutters

Cell parts to output. You will need to generate others parts of the cell seperately, it may not work correctly otherwise.


xy-cell-offset

@include xy-cell-offset($n, $gutters, $gutter-type, $breakpoint, $vertical);

Offsets a column to the right/bottom by $n columns.

ParameterTypeDefault ValueDescription
$n Number or List None

Size to offset by. You can pass in any value accepted by the xy-cell() mixin, such as 6, 50%, or 1 of 2.

$gutters Number or Map $grid-margin-gutters

Map of gutters or single value to use for responsive gutters.

$gutter-type Keyword margin

The type of gutter to use. Can be margin or padding

$breakpoint Number or Array or Keyword null

Breakpoint to use for $gutters. It can be a breakpoint name, list of breakpoints or auto for all breakpoints. If a list is given, media-queries will be generated. If using with the breakpoint() mixin this will be set automatically unless manually entered.

$vertical Boolean false

Sets the direction of the offset. If set to true will apply margin-top instead.


Functions

xy-cell-base

xy-cell-base($size)

Returns the appropriate CSS flex value for a cell base.

ParameterTypeDefault ValueDescription
$size Keyword full

The size of your cell. Accepts full, auto, shrink, grow, or any other value representing a cell size (it will be treated as shrink).


xy-cell-gutters

xy-cell-gutters($gutters, $breakpoint)

Calculate the size of a cell gutters.

ParameterTypeDefault ValueDescription
$gutters Number or Map $grid-margin-gutters

Map or single value for gutters.

$breakpoint String null

The name of the breakpoint size in your gutters map to get the size from. If auto, returns the responsive gutters map $gutters. If using with the breakpoint() mixin this will be set automatically unless manually entered.


xy-cell-size

xy-cell-size($size)

Returns the percentage size of a cell.

ParameterTypeDefault ValueDescription
$size Number or List $grid-columns

Size to make the cell. You can pass a value in multiple formats, such as 6, 50%, 1 of 2 or 1/3.


xy-cell-size-css

xy-cell-size-css($size, $gutters, $gutter-type, $breakpoint)

Returns the appropriate CSS value for a cell size.

Gutters-related arguments are required for cells with margin gutters (by default) as the gutter is included in the width.

ParameterTypeDefault ValueDescription
$size Keyword or Number full

The size of your cell. Can be full, auto, shrink or any fraction like 6, 50%, 1 of 2 or 1/2.

$gutters Number or Map $grid-margin-gutters

Map or single value for gutters.

$gutter-type Keyword margin

Type of gutter to output. Accepts margin, padding or none.

$breakpoint String null

The name of the breakpoint size in your gutters map to get the size from. If auto, returns a map of sizes adapted to responsive gutters. If using with the breakpoint() mixin this will be set automatically unless manually entered.


xy-cell-offset

xy-cell-offset($n, $gutters, $gutter-type, $breakpoint)

Returns the appropriate CSS value to offset a cell.

ParameterTypeDefault ValueDescription
$n Number or List None

Size to offset by. You can pass in any value accepted by the xy-cell() mixin, such as 6, 50%, or 1 of 2.

$gutters Number or Map $grid-margin-gutters

Map of gutters or single value to use for responsive gutters.

$gutter-type Keyword margin

The type of gutter to use. Can be margin or padding

$breakpoint String null

The name of the breakpoint size in your gutters map to get the size from. If using with the breakpoint() mixin this will be set automatically unless manually entered.