Skip to content

Instantly share code, notes, and snippets.

@jamesslock
Created February 26, 2014 15:27
Show Gist options
  • Save jamesslock/9231599 to your computer and use it in GitHub Desktop.
Save jamesslock/9231599 to your computer and use it in GitHub Desktop.
Clusterfuck rem mixin
/ Fluid Squares
// -------------------------------------------------------
@mixin box($box-size: 4rem, $fluid: false) {
display: inline-block;
position: relative;
width: $box-size;
text-align: center;
@if($fluid) {
height: 0;
padding-bottom: $box-size;
}
@else {
height: $box-size;
}
.box--diamond__content {
width: $box-size;
height: $box-size;
}
}
// Diamonds
// -------------------------------------------------------
@mixin diamond($degrees: 45deg) {
display: inline-block;
position: relative;
text-decoration: none;
overflow: hidden;
@include rotate($degrees);
.box--diamond__content {
display: table-cell;
vertical-align: middle;
padding: 1rem;
@include rotate(-$degrees);
}
}
// Rem - Px fallback
// -------------------------------------------------------
@function parseInt($n) { /* [2] */
@return $n / ($n * 0 + 1);
}
@mixin rem($property, $values) {
$px : (); /* [3] */
$rem: (); /* [3] */
@each $value in $values { /* [4] */
@if $value == 0 or $value == auto { /* [5] */
$px : append($px , $value);
$rem: append($rem, $value);
}
@else {
$unit: unit($value); /* [6] */
$val: parseInt($value); /* [6] */
@if $unit == "px" { /* [7] */
$px : append($px, $value);
$rem: append($rem, ($val / 10 * 1rem));
}
@if $unit == "rem" { /* [7] */
$px : append($px, ($val * 10 * 1px));
$rem: append($rem, $value);
}
}
}
#{$property}: $px; /* [8] */
#{$property}: $rem; /* [8] */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment