Commit 77bccf89 authored by Mark Otto's avatar Mark Otto

Update grid mixins section of the docs

parent c3b0870e
...@@ -398,8 +398,7 @@ ...@@ -398,8 +398,7 @@
<p>Variables determine the number of columns, the gutter width, and the media query point at which to begin floating columns. We use these to generate the predefined grid classes documented above, as well as for the custom mixins listed below.</p> <p>Variables determine the number of columns, the gutter width, and the media query point at which to begin floating columns. We use these to generate the predefined grid classes documented above, as well as for the custom mixins listed below.</p>
{% highlight scss %} {% highlight scss %}
@grid-columns: 12; @grid-columns: 12;
@grid-gutter-width: 30px; @grid-gutter-width: 1.5rem;
@grid-float-breakpoint: 768px;
{% endhighlight %} {% endhighlight %}
<h4>Mixins</h4> <h4>Mixins</h4>
...@@ -407,155 +406,74 @@ ...@@ -407,155 +406,74 @@
{% highlight scss %} {% highlight scss %}
// Creates a wrapper for a series of columns // Creates a wrapper for a series of columns
.make-row(@gutter: @grid-gutter-width) { .make-row(@gutter: @grid-gutter-width) {
// Then clear the floated columns
.clearfix();
@media (min-width: @screen-sm-min) {
margin-left: (@gutter / -2);
margin-right: (@gutter / -2);
}
// Negative margin nested rows out to align the content of columns
.row {
margin-left: (@gutter / -2); margin-left: (@gutter / -2);
margin-right: (@gutter / -2); margin-right: (@gutter / -2);
} &:extend(.clearfix all);
} }
// Generate the extra small columns // Make the element grid-ready (applying everything but the width)
.make-xs-column(@columns; @gutter: @grid-gutter-width) { .make-col(@gutter: @grid-gutter-width) {
position: relative; position: relative;
// Prevent columns from collapsing when empty
min-height: 1px;
// Inner gutter via padding
padding-left: (@gutter / 2);
padding-right: (@gutter / 2);
// Calculate width based on number of columns available
@media (min-width: @grid-float-breakpoint) {
float: left;
width: percentage((@columns / @grid-columns));
}
}
// Generate the small columns
.make-sm-column(@columns; @gutter: @grid-gutter-width) {
position: relative;
// Prevent columns from collapsing when empty
min-height: 1px;
// Inner gutter via padding
padding-left: (@gutter / 2);
padding-right: (@gutter / 2);
// Calculate width based on number of columns available
@media (min-width: @screen-sm-min) {
float: left; float: left;
width: percentage((@columns / @grid-columns));
}
}
// Generate the small column offsets
.make-sm-column-offset(@columns) {
@media (min-width: @screen-sm-min) {
margin-left: percentage((@columns / @grid-columns));
}
}
.make-sm-column-push(@columns) {
@media (min-width: @screen-sm-min) {
left: percentage((@columns / @grid-columns));
}
}
.make-sm-column-pull(@columns) {
@media (min-width: @screen-sm-min) {
right: percentage((@columns / @grid-columns));
}
}
// Generate the medium columns
.make-md-column(@columns; @gutter: @grid-gutter-width) {
position: relative;
// Prevent columns from collapsing when empty
min-height: 1px; min-height: 1px;
// Inner gutter via padding
padding-left: (@gutter / 2); padding-left: (@gutter / 2);
padding-right: (@gutter / 2); padding-right: (@gutter / 2);
// Calculate width based on number of columns available
@media (min-width: @screen-md-min) {
float: left;
width: percentage((@columns / @grid-columns));
}
}
// Generate the medium column offsets
.make-md-column-offset(@columns) {
@media (min-width: @screen-md-min) {
margin-left: percentage((@columns / @grid-columns));
}
} }
.make-md-column-push(@columns) {
@media (min-width: @screen-md-min) {
left: percentage((@columns / @grid-columns));
}
}
.make-md-column-pull(@columns) {
@media (min-width: @screen-md-min) {
right: percentage((@columns / @grid-columns));
}
}
// Generate the large columns
.make-lg-column(@columns; @gutter: @grid-gutter-width) {
position: relative;
// Prevent columns from collapsing when empty
min-height: 1px;
// Inner gutter via padding
padding-left: (@gutter / 2);
padding-right: (@gutter / 2);
// Calculate width based on number of columns available // Set a width (to be used in or out of media queries)
@media (min-width: @screen-lg-min) { .make-col-span(@columns) {
float: left;
width: percentage((@columns / @grid-columns)); width: percentage((@columns / @grid-columns));
}
} }
// Generate the large column offsets // Get fancy by offsetting, or changing the sort order
.make-lg-column-offset(@columns) { .make-col-offset(@columns) {
@media (min-width: @screen-lg-min) {
margin-left: percentage((@columns / @grid-columns)); margin-left: percentage((@columns / @grid-columns));
}
} }
.make-lg-column-push(@columns) { .make-col-push(@columns) {
@media (min-width: @screen-lg-min) {
left: percentage((@columns / @grid-columns)); left: percentage((@columns / @grid-columns));
}
} }
.make-lg-column-pull(@columns) { .make-col-pull(@columns) {
@media (min-width: @screen-lg-min) {
right: percentage((@columns / @grid-columns)); right: percentage((@columns / @grid-columns));
}
} }
{% endhighlight %} {% endhighlight %}
<h4>Example usage</h4> <h4>Example usage</h4>
<p>You can modify the variables to your own custom values, or just use the mixins with their default values. Here's an example of using the default settings to create a two-column layout with a gap between.</p> <p>You can modify the variables to your own custom values, or just use the mixins with their default values. Here's an example of using the default settings to create a two-column layout with a gap between.</p>
{% highlight scss %} {% highlight scss %}
.wrapper { .container {
max-width: 60em;
.make-container();
}
.row {
.make-row(); .make-row();
} }
.content-main { .content-main {
.make-lg-column(8); .make-col();
@media (max-width: 32em) {
.make-col-span(6);
}
@media (min-width: 32.1em) {
.make-col-span(8);
}
} }
.content-secondary { .content-secondary {
.make-lg-column(3); .make-col();
.make-lg-column-offset(1);
@media (max-width: 32em) {
.make-col-span(6);
}
@media (min-width: 32.1em) {
.make-col-span(4);
}
} }
{% endhighlight %} {% endhighlight %}
{% highlight html %} {% highlight html %}
<div class="wrapper"> <div class="container">
<div class="row">
<div class="content-main">...</div> <div class="content-main">...</div>
<div class="content-secondary">...</div> <div class="content-secondary">...</div>
</div>
</div> </div>
{% endhighlight %} {% endhighlight %}
</div> </div>
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// //
// Generate semantic grid columns with these mixins. // Generate semantic grid columns with these mixins.
// Centered container element
.make-container(@gutter: @grid-gutter-width) { .make-container(@gutter: @grid-gutter-width) {
margin-right: auto; margin-right: auto;
margin-left: auto; margin-left: auto;
...@@ -11,7 +10,6 @@ ...@@ -11,7 +10,6 @@
&:extend(.clearfix all); &:extend(.clearfix all);
} }
// Creates a wrapper for a series of columns
.make-row(@gutter: @grid-gutter-width) { .make-row(@gutter: @grid-gutter-width) {
margin-left: (@gutter / -2); margin-left: (@gutter / -2);
margin-right: (@gutter / -2); margin-right: (@gutter / -2);
...@@ -29,12 +27,15 @@ ...@@ -29,12 +27,15 @@
.make-col-span(@columns) { .make-col-span(@columns) {
width: percentage((@columns / @grid-columns)); width: percentage((@columns / @grid-columns));
} }
.make-col-offset(@columns) { .make-col-offset(@columns) {
margin-left: percentage((@columns / @grid-columns)); margin-left: percentage((@columns / @grid-columns));
} }
.make-col-push(@columns) { .make-col-push(@columns) {
left: percentage((@columns / @grid-columns)); left: percentage((@columns / @grid-columns));
} }
.make-col-pull(@columns) { .make-col-pull(@columns) {
right: percentage((@columns / @grid-columns)); right: percentage((@columns / @grid-columns));
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment