Last active
December 21, 2015 15:28
-
-
Save kawasako/6326361 to your computer and use it in GitHub Desktop.
@mixin float
This file contains 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
// clearfix | |
@mixin clearfix { | |
zoom: 1; | |
&:after { | |
content: ""; | |
display: block; | |
clear: both; | |
} | |
} | |
// float | |
@mixin float($selector: ">*", $margin: null , $direction: left, $width: null) { | |
@include clearfix; | |
@content; | |
#{$selector} { | |
margin-#{$direction}: $margin; | |
display: block; | |
float: $direction; | |
&:first-child { | |
margin-#{$direction}: 0; | |
} | |
@if length($width) < 2 { | |
width: $width; | |
} | |
@else { | |
$s: "&:first-child"; | |
@for $i from 1 through length($width) { | |
@if $i > 1 { | |
$s: $s + "+*"; | |
} | |
#{$s} { | |
width: nth($width, $i); | |
} | |
} | |
} | |
} | |
} | |
// Example ul>li*3 | |
ul { | |
@include float(); // width auto | |
@include float($width: 200px 300px 100px); // width fix | |
@include float($margin: 10px); // li+li margin | |
@include float($direction: right); // float right | |
@include float(){ | |
// other style | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment