Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 18th, 2012  |  syntax: None  |  size: 2.45 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //----- Global variables-------------
  2. $mr-grid-width: 1200px !default;    // The wrapper/container size$mr-gutter-width: 20px !default; // The amount of margin between columns
  3. $mr-em-base: 16px !default;
  4. $mr-convert-to: "%" !default;
  5. //----------------------------------
  6.  
  7. @function -mr-grid-col-width($cols, $grid-width:$mr-grid-width, $grid-total-cols:$mr-grid-total-column, $gutter-width: $mr-gutter-width){
  8.   //$cols   The number of columns used to create the current elements width.
  9.  
  10.   @return ($grid-width / $grid-total-cols) * $cols - $gutter-width;
  11. }
  12.  @function mr-remove-unit($target){
  13.    $one:1;
  14.      @if not unitless($target){
  15.       //find out the unit of measurement being used
  16.       @if (unit($target) == "px"){$one:1px;}
  17.       @elseif (unit($target) == "em"){$one:1em;}
  18.       @elseif (unit($target) == "%"){$one:1%;}
  19.       // dividing by the same unit forces sass to return a value with no unit
  20.      @return $target / $one ;
  21.      }
  22.    @else
  23.    {@return $target;}
  24.   }
  25.  
  26.  
  27. @function -mr-calc-elem($target-size,$new-unit:$mr-convert-to,$em-base:$mr-em-base,$context:$mr-grid-width){
  28.  // $context defaults to the container's size
  29.  // $new-unit accepts as values %, em, or px
  30.  
  31.  //if no unit is entered, assume the unit being used is in pixels
  32.    @if unitless($target-size){
  33.     @warn "Assuming #{$target-size} to be in pixels, change to #{$target-size}px or another unit of measurement";
  34.     $target-size: $target-size * 1px;
  35.  }
  36.  
  37.  // remove units to prevent sass errors
  38.  $context:mr-remove-unit($context);
  39.  $em-base:mr-remove-unit($em-base);
  40.  $nounit-target-size: mr-remove-unit($target-size);
  41.  
  42.   @if (unit($target-size) == $new-unit){
  43.       //does not make sense to convert to the same unit, so return the original size
  44.     @return $target-size;
  45.    }
  46.    //convert pixel to percentage
  47.    @elseif (unit($target-size) == "px" and $new-unit =="%"){
  48.     @return  percentage($nounit-target-size / $context);
  49.    }
  50.  
  51.     //---convert pixel to em
  52.    @elseif (unit($target-size) == "px" and $new-unit =="em"){
  53.      // multiplying by 1em forces sass to add the em unit to the result
  54.     @return ($nounit-target-size / $em-base)* 1em;
  55.    }
  56.    //---convert em to px
  57.    @elseif (unit($target-size) == "em" and $new-unit =="px"){
  58.  
  59.     // multiplying by 1px forces sass to add the px unit to the result,
  60.     @return ($nounit-target-size * $em-base) * 1px;
  61.    }
  62.    @else {
  63.       @warn "The unit being used is #{unit($target-size)}, #{$target-size} should be in px, %, or em"  ;
  64.       @return $target-size;
  65.     }
  66. }