Skip to content

Instantly share code, notes, and snippets.

@kawasako
Last active December 21, 2015 15:28
Show Gist options
  • Save kawasako/6326361 to your computer and use it in GitHub Desktop.
Save kawasako/6326361 to your computer and use it in GitHub Desktop.
@mixin float
// 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