Last active
August 29, 2015 14:00
-
-
Save torounit/11201725 to your computer and use it in GitHub Desktop.
おれおれ Grid System Mixin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ================================= | |
// | |
// #Layout Grid Mix-in. | |
// | |
// ##Params | |
// * $unitClassName グリッドのclass名 | |
// * $maxCols カラムの分割数 | |
// * $width 横幅 | |
// * $gap カラムの隙間 | |
// | |
// ##Useage | |
// | |
//```` | |
//.gird { | |
// @include gird( "unit", 12, 940px, 20px ); | |
//} | |
//.f-gird { | |
// @include gird( "unit", 4, 100%, 2% ); | |
//} | |
// | |
//```` | |
// ================================= | |
// | |
@mixin grid( $unitClassName, $maxCols, $width, $gap) { | |
$gap: percentage($gap / $width); | |
%unit { | |
@include box-sizing(border-box); | |
@include pie-clearfix; | |
float: left; | |
> a:only-child img, | |
> img:only-child { | |
vertical-align: bottom; | |
} | |
} | |
@include pie-clearfix; | |
margin: 0 -#{$gap}; | |
$total: 100% + $gap * 2; | |
width: $total; | |
.#{$unitClassName} { | |
@extend %unit; | |
margin-left: $gap * 100% / $total; | |
margin-bottom: $gap; | |
} | |
@for $cols from 2 through $maxCols { | |
$baseColWidth: (100% - $gap * ($cols - 1)) / $cols; | |
@for $i from 1 through $cols { | |
$colWidth: $baseColWidth * $i + $gap * (($i - 1) - 2 / $cols); | |
.#{$unitClassName}_#{$i}of#{$cols} { | |
width: #{$colWidth}; | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
すると、こんなかんじに展開されます。960gs等のような、一番外側のmarginはありません。