包详细信息

suitcss-components-grid

suitcss1.9kMIT4.0.0

SUIT CSS component for grid layouts

browser, css-components, grid, suitcss

自述文件

SUIT CSS components-grid

Build Status

A CSS grid component. The grid makes use of flexbox and box-sizing to provide features that float-based layouts cannot.

N.B. This component relies on particular dimensions being applied to cells in the grid via other classes. For example, suitcss-utils-size.

Read more about SUIT CSS.

Installation

  • npm: npm install suitcss-components-grid
  • Download: zip

Features

  • Fluid layout.
  • Intelligent cell wrapping.
  • Evenly fill cell spacing
  • Equal height columns
  • Horizontal centering of cells.
  • Custom vertical alignment of cells (top, bottom, or middle).
  • Cell width is controlled independently of grid gutter.
  • Infinite nesting.

Available classes

  • Grid: core component
  • Grid--alignCenter: center-align all child cells
  • Grid--alignRight: right-align all child cells
  • Grid--alignMiddle: middle-align all child cells
  • Grid--alignBottom: bottom-align all child cells
  • Grid--fill: evenly distribute space amongst all child cells
  • Grid--fit: fit cells to their content
  • Grid--equalHeight: all child cells match height of the tallest
  • Grid--withGutter: adds a gutter between cells

Configurable variables

  • --Grid-gutter-size: the width of the gutter applied by the Grid--withGutter modifier class.

Use

A simple grid is easy to create. A grid container can have any number of child cells. When used with Grid--fill space is evenly distributed without need for sizing utilities.

Note Elements that are direct descendants of Grid will be flex items. It's recommended to use an element that can easily have classes attached later if needed, such as u-sizeFill or u-flexJustifyCenter

<div class="Grid Grid--fill Grid--withGutter">
  <div><!-- cell content --></div>
  <div><!-- cell content --></div>
  <div><!-- cell content --></div>
  <div><!-- cell content --></div>
</div>

For more granular control over layout make use of modifiers and sizing utilities.

<div class="Grid [Grid--alignCenter|Grid--alignRight|Grid--alignMiddle|Grid--alignBottom|Grid--fill|Grid--fit|Grid--equalHeight]">
  <div class="u-size1of2 u-lg-size6of12"></div>
  <div class="u-size1of2 u-lg-size4of12"></div>
  <div class="u-size1of3 u-lg-size2of12"></div>
  <div class="u-size1of3"></div>
</div>

Fit cells to their content and allow others to fill the remaining space.

<div class="Grid">
  <div class="u-sizeFit">Fit to content</div>
  <div class="u-sizeFill">Take up remaining space</div>
</div>

Widths and offsets

Cell widths and offsets can be controlled using the responsive sizing utilities and responsive offset utilities, respectively.

One limitation of creating grid gutters in the manner shown above is that it prevents any offset utilities applied directly to the Grid component from functioning as expected.

GOOD:

<div class="Grid Grid--withGutter">
  <div class="u-size1of2 u-before1of4 u-after1of4">
    {{>partial}}
  </div>
</div>

BAD:

<div class="Grid Grid--withGutter u-before1of4 u-after1of4">
  <div>
    {{>partial}}
  </div>
</div>

You can nest grids in any context, including one that uses dimension or offset utilities, but keep in mind that the dimensions will be relative to the grid's width, and not the width of the whole application.

<div class="u-before1of4 u-after1of4">
  <div class="Grid Grid--withGutter">
    <div class="u-size1of2"> <!-- 50% of the width of the Grid -->
      {{>partial}}
    </div>
  </div>
</div>

Testing

Install Node (comes with npm).

npm install

To generate a build:

npm run build

To lint code with postcss-bem-linter and stylelint

npm run lint

To generate the testing build:

npm run build-test

To watch the files for making changes to test:

npm run watch

Basic visual tests are in test/index.html.

Browser support

  • Google Chrome (latest)
  • Opera (latest)
  • Firefox (latest)
  • Safari 6.2+
  • Internet Explorer 10+
  • iOS 7+
  • Android 4.4+
  • Windows Phone 8.1+

Refer to the caniuse page for flexbox

更新日志

HEAD

4.0.0 (January 25, 2018)

  • Rename Grid-fit to Grid-fill and repurpose to match sizing utility behavior #51

3.0.3 (May 05, 2016)

  • Fix issue with overflowing elements #44
  • Fix issue with offsets and no explicit cell width #43

3.0.2 (February 15, 2016)

  • Update stylelint-config-suitcss to 4.0.0
  • Update preprocessor to 1.0.0
  • Fix maxlen warning on comments
  • Remove unused stylelint package as this is included with the suitcss-preprocessor.

3.0.1 (December 02, 2015)

  • Upgrade to ^0.8.0 suitcss-preprocessor
  • Ensure Grid conforms to SUIT CSS stylelint rules
  • Add license field to package.json

3.0.0 (November 01, 2015)

  • Switch to flexbox for layout
  • Add Grid--fit and Grid--equalHeight modifiers
  • Use PostCSS instead of suitcss-preprocessor

2.0.2 (October 28, 2014)

  • Add support for JS bundling.

2.0.1 (July 8, 2014)

  • Support different unit types for grid gutter width.

2.0.0 (June 26, 2014)

  • Change variable names.

1.4.1 (June 24, 2014)

  • Add .css extension to imports for interoperability.

1.4.0 (June 22, 2014)

  • npm-based workflow.
  • Add new preprocessor build tools.

1.3.0 (May 15, 2014)

  • Use latest variable syntax.

1.2.0 (April 5, 2014)

  • Add configurable variables.
  • Add Grid-withGutter modifier.
  • Add npm support.

1.1.0 (November 20, 2013)

  • Add Grid--alignMiddle and Grid--alignBottom modifiers.
  • Fix Component(1) install and use it in development.
  • Rewrite the visual tests using 'suit-test'.

1.0.0 (October 18, 2013)

  • Improve documentation.
  • Improve whitespace collapse reliability by using font-size:0 (no IE 8 support).
  • Add Grid--alignRight to right-align grid cells.
  • Rename Grid--center to Grid-alignCenter.
  • Add utils-offset to development dependencies.

0.3.2 (September 1, 2013)

  • Add -webkit-box-sizing for Android 2/3.
  • Add CSS linting and configuration.
  • Add Component(1) support.
  • Update utils-dimension to v0.4.x.
  • Update Bower install directory path.

0.3.1 (May 26, 2013)

  • Rename component.json to bower.json.

0.3.0 (March 19, 2013)

  • Remove use of Grid as a child of Grid.
  • Remove default gutter.

0.2.0 (March 7, 2013)

  • Add a test file.
  • Fix whitespace collasping in Chrome 25.
  • Change class naming convention.
  • Remove unit classes; now part of a 'dimension' utility.

0.1.1 (February 25, 2013)

  • Fix typo in unit class name.

0.1.0 (January 22, 2013)

  • Initial public release.