Skip to content

Instantly share code, notes, and snippets.

@jakob-e
Last active August 29, 2015 14:08
Show Gist options
  • Save jakob-e/0be6f58e463a222b6193 to your computer and use it in GitHub Desktop.
Save jakob-e/0be6f58e463a222b6193 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
MEDIA EXTENDS AND SCALING
- Added exclude
// ----
// Sass (v3.3.14)
// Compass (v1.0.1)
// ----
$root: "";
@function pow($x, $y) {
$ret: 1;
@if $y > 0 { @for $i from 1 through $y { $ret: $ret * $x; } }
@else { @for $i from $y to 0 { $ret: $ret / $x; } }
@return $ret;
}
@function xto-list($args...) {
@return append((), $args);
}
@function to-list($value) {
@return if(type-of($value) != list, ($value,), $value);
}
$__ratios:(
// label : (ratio or list, index)
golden : (1.618, 0),
fifth : (1.500, 0)
);
@function scale($offset, $label){
$ratio: nth(map-get($__ratios, $label),1);
$offset: $offset +nth(map-get($__ratios, $label),2);
@return pow($ratio, $offset);
}
// ====================================================================================
// Media
//
// Variable to keep the current media context
$__media_context: "";
// Simple media mixin
@mixin media($breakpointkeys...){
@each $key, $value in $breakpointkeys {
$__media_context: $key !global; // set flag on enter
@media #{map-get($breakpoints, $key)}{ @content; }
$__media_context: "" !global; // reset on exit
}
}
// Function to get the current media context
@function media-context($context:null){
@if $context { @return $__media_context == $context; }
@return $__media_context;
}
// Returns a list of breakpoint keys
// without the ones passed
@function exclude($keys...){
// When excluding media we need to add _root
$map:map-merge($breakpoints, ("":""));
$map:map-remove($map, $keys); // remove items
@return map-keys($map);
}
// Mixin to clone placeholders to each media directive
// - cuts down on the amount of generated media queries :)
@mixin extends(){
@content;
@each $key in $breakpoints {
@include media($key){ @content; }
}
}
// Mixin to create media placeholders
// Note! passing contexts will only create placholders in the
//
@mixin new-extend($extend-name, $context...){
@if length($context) > 0 {
$context:if(type-of(nth($context,1))==list,nth($context,1),$context);
@if index($context, media-context()){
%#{ media-context() + $extend-name }{ @content; }
}
} @else {
%#{ media-context() + $extend-name }{ @content; }
}
}
// Mixin to extend existing media placeholders
@mixin extend($extend-name){
& {
@extend %#{ media-context() + $extend-name } //!optional;
}
}
// Define your breakpoints
$breakpoints:(
all : "all"
, mobile : "(max-width: 480px)"
, palm : "(min-width: 481px) and (max-width: 680px)"
, tablet : "(min-width: 681px) and (max-width: 960px)"
, desktop : "(min-width: 961px) and (max-width: 1200px)"
, large : "(min-width: 1201px)"
);
@mixin breakpoint($name, $value) {
@if map-has-key($breakpoints, $name) { @error 'breakpoints `#{$name}` already defined.'; }
$breakpoints: map-merge($breakpoints, ($name: $value)) !global;
}
@include breakpoint(tupac, '(orientation: landscape)');
@function media-prop($property){
}
@include extends(){
@include new-extend(h1, exclude(desktop, tablet)){
font-size:scale(1 , golden);
}
@include new-extend(h1, desktop, tablet) {
font-size:scale(1, fifth);
}
@include new-extend(h2) { font-size:scale(9, golden); }
@include new-extend(h3) { font-size:scale(1, golden); }
@include new-extend(h4) { font-size:scale(0, golden); }
}
h1 { @extend %h1; }
h2 { @extend %h2; }
@include media(mobile){
Mobile { @include extend(h1); }
}
@include media(desktop){
content:desktop;
Desktop { @include extend(h1); }
}
@include media(tablet){
content:tablet;
TAB { @include extend(h1); }
}
@include media(tupac){
content:tupac;
tupac { @include extend(h1); }
}
@function font-size($context: media-context()){
@return map-get((
all : 2.5em
, mobile : 1.5em
, palm : 1.5em
, tablet : 2.0em
, desktop : 2.5em
, large : 3.0em
), $context);
}
@include media(mobile){
font { font-size:font-size(); } // font-size: 3em;
}
h1 {
font-size: 1.618;
}
h2 {
font-size: 75.99879;
}
@media (max-width: 480px) {
Mobile {
font-size: 1.618;
}
}
@media (min-width: 681px) and (max-width: 960px) {
TAB {
font-size: 1.618;
}
TAB {
font-size: 1.5;
}
}
@media (min-width: 961px) and (max-width: 1200px) {
Desktop {
font-size: 1.618;
}
Desktop {
font-size: 1.5;
}
}
@media (orientation: landscape) {
tupac {
font-size: 1.618;
}
}
@media (min-width: 961px) and (max-width: 1200px) {
content: desktop;
}
@media (min-width: 681px) and (max-width: 960px) {
content: tablet;
}
@media (orientation: landscape) {
content: tupac;
}
@media (max-width: 480px) {
font {
font-size: 1.5em;
}
}
MEDIA EXTENDS AND SCALING
- Added exclude
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment