Sha256: 0cba1f808a74f16a66a5f0ac825546ba43c76cd67c836b88bb2ad221f50c2ec9

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 KB

Contents

// Android uses Density Independent Pixels (dip or dp) as the units defined in the W3C spec for pixels and pixels (px) as hardware defined units.
// This project aims to bring these two units to CSS using Sass functions and mixins.

// Base size should be the em height on the html element
$base-size: 16px !default

// Convert dips to em, rem, or px
$dip-conversion: em !default

// Context offset
$em-offset: 1 !default

// Convert dips to em or rem (px will not work because the W3C spec considers px to be density independent pixels)
$px-conversion: em !default

@function dip($number, $em-offset, $dip-conversion)
  $unitless-em-offset: $em-offset / 1em
  @if unitless($em-offset)
    $unitless-em-offset: $em-offset
  @if $dip-conversion == px
    @return $number * 1px
  @if $dip-conversion == em
    @return ($number / ($base-size / 1px)) * (1 / $unitless-em-offset) * 1em
  @if $dip-conversion == rem
    @return $number / ($base-size / 1px) * 1rem

@function dp($number, $em-offset, $dip-conversion)
  @return dip($number, $em-offset, $dip-conversion)

// Simple px => em conversion
@function em($number, $em-offset)
  @return dip($number, $em-offset, em)

// Simple px => rem conversion
@function em($number, $em-offset)
  @return dip($number, $em-offset, rem)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
seasons-0.9.3.beta16 stylesheets/seasons/tools/_relative-pixels.sass
seasons-0.9.3.beta15 stylesheets/seasons/tools/_relative-pixels.sass
seasons-0.9.3.beta14 stylesheets/seasons/tools/_relative-pixels.sass
seasons-0.9.3.beta13 stylesheets/seasons/tools/_relative-pixels.sass
seasons-0.9.3.beta12 stylesheets/seasons/tools/_relative-pixels.sass