-
[Atomic classes] (#2-atomic-classes)
2.A [Quick start] (#2a-quick-start)
2.B Add a gutter
2.C Limit the column number
2.D Set a minimum card width
2.E Set a maximum card width
2.F Prevent last row expansion -
[CSS Rules] (#3-css-rules)
3.A [Quick start] (#3a-quick-start)
3.B Add a gutter
3.C Limit the column number
3.D Set a minimum card width
3.E Set a maximum card width
3.F Prevent last row expansion -
[Sass] (#4-sass)
4.A [Quick start] (#4a-quick-start)
4.B Prevent last row expansion -
[Browser Compatibility] (#browser-compatibility)
-
Installation
Install chewing-grid via bower and add it to bower.json dependencies
bower install chewing-grid --save
- Atomic classes
Let sart with the minimum markup:
<link rel="stylesheet" type="text/css" href="build/chewing-grid-atomic.css"/>
<ul class="chew-row">
<li class="chew-cell">
<div class="chew-card">1</div>
</li>
<li class="chew-cell">
<div class="chew-card">2</div>
</li>
<li class="chew-cell">
<div class="chew-card">3</div>
</li>
<!-- [...] -->
</ul>
Add a chew-row--gutter
markup, to add a gutter between cards:
<!-- Ex: Add a 1em gutter -->
<ul class="chew-row chew-row--gutter">
<!-- [...] -->
</ul>
Add a chew-row--col-{n}
markup, to set a column limit:
<!-- Ex: 4 columns maximum -->
<ul class="chew-row chew-row--col-4">
<!-- [...] -->
</ul>
Add a chew-row--card-min-{width}
markup, to set a minimum card width:
<!-- Ex: card width of 300px minimum -->
<ul class="chew-row chew-row--card-min-300">
<!-- [...] -->
</ul>
Add a chew-row--card-max-{width}
markup, to set a maximum card width:
<!-- Ex: card width of 500px maximum -->
<ul class="chew-row chew-row--card-max-500">
<!-- [...] -->
</ul>
Add some chew-cell--ghost
markup.
<ul class="chew-row chew-row--col-3">
<li class="chew-cell">
<div class="chew-card">1</div>
</li>
<li class="chew-cell">
<div class="chew-card">2</div>
</li>
<li class="chew-cell">
<div class="chew-card">3</div>
</li>
<!-- [...] -->
<li class="chew-cell chew-cell--ghost"></li>
<li class="chew-cell chew-cell--ghost"></li>
</ul>
You have to add at least column-max-count - 1
items.
- CSS Rules
Let sart with the minimum markup:
<link rel="stylesheet" type="text/css" href="build/chewing-grid.css"/>
<ul class="chew-row myCardLit">
<li class="chew-cell">
<div class="chew-card">1</div>
</li>
<li class="chew-cell">
<div class="chew-card">2</div>
</li>
<li class="chew-cell">
<div class="chew-card">3</div>
</li>
<!-- [...] -->
</ul>
Change the cell padding
, to add a gutter between cards:
.myCardLit .chew-cell {
padding: 0.5em; /* vertical & horizontal gutter of 1em (= 2 * 0.5em) */
}
Change the cell width
to set a column limit:
.myCardLit .chew-cell {
width: 25%; /* 4 columns */
}
Change the cell min-width
to set a card width constraint (including gutter):
.myCardLit .chew-cell {
min-width: 300px
}
Change the card max-width
to set a card width constraint:
.myCardLit .chew-card {
max-width: 300px
}
Add some chew-cell--ghost
markup.
<ul class="chew-row chew-row--col-3">
<li class="chew-cell">
<div class="chew-card">1</div>
</li>
<li class="chew-cell">
<div class="chew-card">2</div>
</li>
<li class="chew-cell">
<div class="chew-card">3</div>
</li>
<!-- [...] -->
<li class="chew-cell chew-cell--ghost"></li>
<li class="chew-cell chew-cell--ghost"></li>
</ul>
You have to add at least column-max-count - 1
items.
- Sass
Let sart with the our custom markup:
<ul class="character-row">
<li class="character-cell">
<div class="character-card">1</div>
</li>
<li class="character-cell">
<div class="character-card">2</div>
</li>
<li class="character-cell">
<div class="character-card">3</div>
</li>
<!-- [...] -->
</ul>
Generate our associated custom classes:
@import 'src/mixins/grid.mixin';
@include chewing-grid(
$prefix: 'character-',
$column-max-count: 4,
$card-gutter: 1em,
$card-min-width: 200px,
$card-max-width: 300px
);
Add some chew-cell--ghost
markup.
<ul class="chew-row chew-row--col-3">
<li class="chew-cell">
<div class="chew-card">1</div>
</li>
<li class="chew-cell">
<div class="chew-card">2</div>
</li>
<li class="chew-cell">
<div class="chew-card">3</div>
</li>
<!-- [...] -->
<li class="chew-cell chew-cell--ghost"></li>
<li class="chew-cell chew-cell--ghost"></li>
</ul>
You have to add at least column-max-count - 1
items.
chewing-grid have some workarounds to improve compatibility:
- no
-webkit-
prefix:
Safari does not handleflex-wrap
property when a flex item has amin-width
and a percentflex-basis
. cf. bug tracking. - no use of
calc()
:
IE 10-11 ignorecalc()
functions used inflex
shorthand declarations. cf. bug documentation. - no use of
flex-basis
:
IE 10-11 ignorebox-sizing: border-box
when size set withflex-basis
. cf. bug documentation. - no
height: 100%
on card:
Chrome doesn't support percent height on felx items childs. cf. bug tracking. - Use
display: inline-block
and `media-queries:
To improve the user experience on browsers that doest not support flexbox.