Git Product home page Git Product logo

sassmq's Introduction

SASS Flexible Media Queries Mixin-Andres Gallo

There are many sass mixins to make media queries all over the internet but all of them seem to support only one media query at a time. It is for this reason I wrote this mixin. For more complex layouts for example there are cases where the same css is needed in two different media queries. While it is possible to call the current media query mixins twice (once for each of the two different media queries), the duplicate output is undesireable as it creates unecessary duplicate code.

Using the script

  • First import the mixin....
  • Should you want to skip the instructions there are some examples below ...oh yeee!
  • To use the script simply call the sass mixing 'media' and pass it a single or multiple lists followed by an empty list to tell sass to iterate through them 2 level list. The syntax for the lists is ().
  • Each list corresponds to each media query.

Parameters for each media query- in order in which they may be passed. NONE ARE REQUIRED.

  • min (int)
  • max (int)
  • format (String) - Defaults to screen
  • orientation (String)

Examples

SCSS for devices with a width greater than or equal to 600px AS WELL AS devices with a width of lesser or equal to 599 in portrait mode

.TEST {//Multiple media query example
  @include media( (600)(null 599 null portrait)() ){
    color: green;
  }
}

CSS output

@media only screen and (min-width: 600px), only screen and (max-width: 599px) and (orientation: portrait) {
  .TEST {
    color: green;
  }
} 

SCSS for print devices

@include media( (null null print null)() ){
  .TESTB {
    color: red;//Not that color matters in most printer stylesheets
  }
}

CSS output

@media only print {
  .TESTB {
    color: red;
  }
}

Good example showing using multiple lists and their merged media query

@include media( (600)(600 1000)(600 1000 print)(600 1000 print landscape) ){
  .TESTB {
    color: orange;
  }
}

CSS output

@media only screen and (min-width: 600px), only screen and (min-width: 600px) and (max-width: 1000px), only print and (min-width: 600px) and (max-width: 1000px) {
  .TESTB {
    color: orange;
  }
}

sassmq's People

Contributors

andresgallo avatar

Watchers

James Cloos avatar  avatar

Forkers

roshow

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.