Skip to content

Instantly share code, notes, and snippets.

@stowball
Last active December 18, 2015 02:29
Show Gist options
  • Select an option

  • Save stowball/5711299 to your computer and use it in GitHub Desktop.

Select an option

Save stowball/5711299 to your computer and use it in GitHub Desktop.
Suzi's Media Query mixins
@mixin media-query($value, $ltie9: true, $operator: $min, $px: false) {
@if ($operator == $max and $value < $site-width) {
// Do nothing
}
@else {
@if ($ltie9 == true) {
.ltie9 & {
@content;
}
}
}
@if ($px == false) {
@media (#{$operator} #{em($value)}) {
@content;
}
}
@else {
@media (#{$operator} #{strip-units($value)}px) {
@content;
}
}
}
@mixin media-query-and($first-value, $second-value, $ltie9: true, $first-operator: $min, $second-operator: $max, $px: false) {
@if ($ltie9 == true and ($second-value >= $site-width)) {
.ltie9 & {
@content;
}
}
@if ($px == false) {
@media (#{$first-operator} #{em($first-value)}) and (#{$second-operator} #{em($second-value)}) {
@content;
}
}
@else {
@media (#{$first-operator} #{strip-units($first-value)}) and (#{$second-operator} #{strip-units($second-value)}) {
@content;
}
}
}
@mixin media-query-retina {
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi), (min-resolution: 2dppx) {
@content;
}
}
@joeldbirch
Copy link
Copy Markdown

Here's a simplified (!) version of what I'm using. Note that two separate css files are output, each of them without duplicate rules. Also means you can use +respond-to(obsolete) to quarantine IE hacks to the oldIE css file.

$bp05: 28em
$bp1: 42em
$bp2: 56em

=respond-to( $media )
  @if $ie
    @if $media != smallest
      @if $media != onlylap
        @if $media != hires
          @content

  @else if $media == onlylap
    @media only screen and (min-width: $bp1) and (max-width: $bp2)
      @content
  @else if $media == widepalm
    @media only screen and (min-width: $bp05)
      @content
  @else if $media == lap
    @media only screen and (min-width: $bp1)
      @content
  @else if $media == desk
    @media only screen and (min-width: $bp2)
      @content
  @else if $media == smallest
    @media only screen and (max-width: $bp1 - .001em)
      @content
  @else if $media == hires
    @media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min-resolution: 144dpi)
      @content

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment