mq-sass
mq-sass is a Sass library to help you manage your responsive breakpoints and easily generate media queries.
Requirements
- Sass 3.3+
- SCSS syntax
Installation
npm install mq-sass
yarn get mq-sass
bower install css-mq-sass
Also available as a Ruby gem to use within your Rails application—see below for more information.
Or to manually install it, download and unzip the source files, then copy the files from the stylesheets/mq-sass
directory into your project.
- Import the
_mq-sass.scss
file into your project.
;
If you're using gulp, Grunt, Compass, or alike, include mq-sass:
// gulp-sass gulpfile.js // grunt-sass Gruntfile.jsoptions: includePaths: 'node_modules/mq-sass/stylesheets'
# Compass config.rbadd_import_path "node_modules/mq-sass/stylesheets"
Install for Ruby on Rails
- Add mq-sass to your Gemfile.
gem 'mq-sass'
- Run
bundle install
. - Include mq-sass by using Sass’s native
@import
*
// application.scss ;
* More information on why Sass’s native @import
+ why you should ditch Sprockets directives altogether.
Documentation
Settings
; ;; ;
mq($breakpoint, $minmax, $widthheight)
Mixin
$breakpoint
- The first parameter,
$breakpoint
, accepts pre-defined values from the$mq-breakpoints();
map, which is set by default as above in Settings.
Example:
/* Resulting CSS */{
You can also customize your own breakpoints.
;
$breakpoint
also accepts other pre-defined values:
- portrait
- landscape
- retina
Example:
/* Resulting CSS */{{
$breakpoint
accepts custom values in px.
Example:
/* Resulting CSS */{
Note: You can also use unitless pixel values: @include mq(700) {}
$minmax
By default, media queries are mobile first (min-width
).
$minmax
accepts values min
or max
, which will result in min-width:
or max-width:
respectively. If left blank, it falls back to the default, min
.
Example:
/* Resulting CSS */{{
$widthheight
By default, media queries that are generated are (min/max-width
).
$widthheight
accepts values width
or height
, which results in min/max-width:
or min/max-height:
respectively. If left blank, it falls back to the default, width
.
Example:
/* Resulting CSS */{{
ems
To have media queries in ems, set $mq-ems: true;
. The default em base is 16px
. You can change it by setting $mq-em-base
to the pixel value of your choosing.
Examples:
;
/* Resulting CSS */{
;;
/* Resulting CSS */{
media
By default the media is specified for only screen
. For some reason if you'd like to change it or remove it completely, you can do so by changing the setting $mq-media
:
;
/* Resulting CSS */{}
; // or false
/* Resulting CSS */{}
mq-get($breakpoint, $ems)
function
Returns the value of the breakpoint in pixels (by default) or ems.
.example
$breakpoint
$breakpoint
accepts only pre-defined keys from the $mq-breakpoints();
map.
; .example .example2
/* Resulting CSS */
$ems
$ems
is a boolean (false
or true
, false
by default) and dictates whether or not the return is in pixels or ems.
.example .example-ems
/* Resulting CSS */
Notes
License
The MIT License
Copyright © 2014–2016 Jonathan Suh (@jonsuh)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.