Sha256: 3587a3faa0124c340d337c749dd1ece40d1edc563327242ba4a2d9534003a58a

Contents?: true

Size: 1.83 KB

Versions: 5

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

5 entries across 5 versions & 1 rubygems

Version Path
persistentgrid-0.0.1.beta.9 scss/pg/helpers/mixins/_units.scss
persistentgrid-0.0.1.beta.8 scss/pg/helpers/mixins/_units.scss
persistentgrid-0.0.1.beta.3 scss/pg/helpers/mixins/_units.scss
persistentgrid-0.0.1.beta.2 scss/pg/helpers/mixins/_units.scss
persistentgrid-0.0.1.beta.1 scss/pg/helpers/mixins/_units.scss