Last active
December 15, 2015 11:39
-
-
Save jimmynotjim/5254575 to your computer and use it in GitHub Desktop.
PX to % converter mixin. Example shows how you could build a grid with it. Can take any property so you don't need separate mixins for widths, margins or positioning properties (left, right, etc)
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
$page: 960; //This is our ideal width | |
$third-col: ( $page - ($gutter * 2) ) / 3; | |
$gutter: 20; //This is our gutter | |
@mixin pxtoper($property, $target, $context) { | |
#{$property}: ($target / $context) * 100%; | |
} |
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
.foo { | |
width: 31.9444444%; | |
margin-left: 2.0833333%; | |
} | |
.foo:first-child { | |
margin-left: 0; | |
} | |
.foo-child { | |
width: 48.9130541%; | |
margin-left: 6.5217405%; | |
} | |
.foo-child:first-child { | |
margin-left: 0; | |
} |
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
.foo { //Lets build a grid that has 20px gutters and three columns at 960px | |
@include fluid(width, $third-col, $page); | |
@include fluid(margin-left, $gutter, $page); | |
&:first-child { | |
margin-left: 0; | |
} | |
} | |
.foo-child { //This is a child column to a 1/3 column | |
@include fluid(width, 150, $third-col); | |
@include fluid(margin-left, $gutter, $third-col); | |
&:first-child { | |
margin-left: 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment