Skip to content

Commit 6d86920

Browse files
author
Cory Simmons
committed
Add clearfix to center()
1 parent e57d3df commit 6d86920

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ figure
6060

6161
`cf()` is just a [clearfix](http://nicolasgallagher.com/micro-clearfix-hack/) mixin since blocks are floated. It's a good idea to give this to the element wrapping your blocks every time.
6262

63+
You can also make use of the `center()` mixin to assign a `max-width` and `margin: auto` to an element and center it on the page. `cf()` will automatically be applied in this case.
64+
65+
```stylus
66+
section
67+
cf($max-size: 1200px, $pad: $gutter)
68+
69+
figure
70+
block('1/2')
71+
```
72+
6373
Every element gets a `float: left` and `margin-right: $gutter` applied to them except the last one in the row. Lost will automatically detect the last item in a row (based on the denominator you passed) and apply a `margin-right: 0` to it by default.
6474

6575
To override this behavior simply pass a `$cycle` param to your `block()`.

scss/lost.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Lost Grid v3.0.2 - https://github.com/corysimmons/lost
1+
// Lost Grid v3.0.3 - https://github.com/corysimmons/lost
22

33
$gutter: 30px !default;
44
$rtl: false !default;
@@ -46,13 +46,18 @@ $rtl: false !default;
4646

4747
/// Horizontally center a container element and apply padding to it.
4848
///
49+
/// @param {unit} $max-size [980px] - A max-width to assign. Can be any unit.
50+
/// @param {unit} $pad [0] - Padding on the left and right of the element. Can be any unit.
51+
/// @param {string} $output [normal] - Determines what type of code to output. Accepts normal (outputs all code), init (only the code to initialize), and bare (just the max-width and padding). Useful for making classes like .center-large, .center-medium, .center-small.
52+
///
4953
/// @example
5054
/// section {
5155
/// @include center(900px);
5256
/// }
5357

5458
@mixin center($max-size: 980px, $pad: 0, $output: normal) {
5559
@if ($output == normal) or ($output == init) {
60+
@include cf;
5661
margin-left: auto;
5762
margin-right: auto;
5863
}

stylus/lost.styl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Lost Grid v3.0.2 - https://github.com/corysimmons/lost
1+
// Lost Grid v3.0.3 - https://github.com/corysimmons/lost
22

33
$gutter = 30px
44
$rtl = false
@@ -41,13 +41,18 @@ cf()
4141
/**
4242
* Horizontally center a container element and apply padding to it.
4343
*
44+
* @param {unit} [$max-size=980px] - A max-width to assign. Can be any unit.
45+
* @param {unit} [$pad=0] - Padding on the left and right of the element. Can be any unit.
46+
* @param {string} [$output=normal] - Determines what type of code to output. Accepts normal (outputs all code), init (only the code to initialize), and bare (just the max-width and padding). Useful for making classes like .center-large, .center-medium, .center-small.
47+
*
4448
* @example
4549
* section
4650
* center(900px)
4751
*/
4852

4953
center($max-size = 980px, $pad = 0, $output = normal)
5054
if $output is normal or $output is init
55+
cf()
5156
margin-left: auto
5257
margin-right: auto
5358
if $output is normal or $output is bare

0 commit comments

Comments
 (0)