Sha256: f5fe8a7d99f1ec302a5733ed6a3150c77dcb99468922fcaaca12573468941c06

Contents?: true

Size: 1.83 KB

Versions: 3

Compression:

Stored size: 1.83 KB

Contents

// /**
//  * @copyright	Copyright (C) 2013 Crossing Hippos - Babs Gösgens. All rights reserved.
//  * @license		GNU General Public License version 2 or later; see LICENSE.txt
//  */
@if $trace-imports { @debug 'imported'; }

// Accepts a value and returns it without a value
@function return-unitless($value)
{
	@if unitless($value) {
		@return $value;
	}

	$unit: unit($value);

	@if $unit=="px" {
		@return $value / 1px;
	}
	@if $unit=="rem" {
		@return $value / 1rem;
	}
	@if $unit=="em" {
		@return $value / 1em;
	}
	@if $unit=="%" {
		@return $value / 1%;
	}
	@if $unit=="pt" {
		@return $value / 1pt;
	}
}


// Use these methods to convert px based units to other units
// There is also a px to px function in case you need to recalculate a px unit for a different context
// Use these methods to convert px based units to other units
// There is also a px to px function in case you need to recalculate a px unit for a different context
@function px-to-percentage($target-px, $context: $base-font-size) {
  @return percentage($target-px / $context);
}
@function px-to-em($target-px, $context: $base-font-size) {
  @return ($target-px / $context) * 1em;
}
@function px-to-rem($target-px, $context: $base-font-size) {
  @return ($target-px / $context) * .1rem;
}
@function px-to-px($target-px, $context: $base-font-size) {
  @return ($target-px / $context) * .1px;
}


// Let this function figure out which conversion function to use.
// Both $target and $context values *must* be in px
@function px-to-relative-size($target-px, $context: $base-font-size, $unit: $font-unit) {

	@if unit($unit)=="%" {
		@return px-to-percentage($target-px, $context);
	}
	@if unit($unit)=="em" {
		@return px-to-em($target-px, $context);
	}
	@if unit($unit)=="rem" {
		@return px-to-rem($target-px, $context);
	}
	@if unit($unit)=="px" {
		@return px-to-px($target-px, $context);
	}
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
persistentgrid-0.0.1.beta.12 scss/persistentgrid/utilities/_units.scss
persistentgrid-0.0.1.beta.11 scss/persistentgrid/utilities/_units.scss
persistentgrid-0.0.1.beta.10 scss/pg/helpers/_units.scss