It's a collection of useful Media Queries mixins for Sass (including iOS devices, TVs and more). Fully customizable and very easy to use.
Using bower:
bower install sass-mediaqueries
Using npm:
npm install sass-mediaqueries
Using curl:
curl -O https://raw.githubusercontent.com/rafalbromirski/sass-mediaqueries/master/_media-queries.scss
Then, at the top of your sass/scss file (ie. application.scss
) add:
@import "media-queries";
mq($args...)
Generator allows you to create custom media-queries mixins by passing keywords arguments based on w3c media features specification (make sure you always provide key and value).
It's also a syntactic sugar for the standard media queries syntax (CSS).
Examples:
@include mq($max-width: 1000px) {
...
}
// will generate
@media only screen and (max-width: 1000px) {
...
}
Creating new mixins (like max-screen
) is even easier:
@mixin max-screen($max)
@include mq($max-width: $max) {
@content;
}
}
// usage
@include max-screen(1000px) {
...
}
// will generate
@media only screen and (max-width: 1000px) {
...
}
Or if you want to change $media-type
and other properies:
@mixin custom-device($min, $max)
@include mq($media-type: 'all', $min-width: $min, $max-width: $max) {
@content;
}
}
// usage
@include custom-device(500px, 1000px) {
...
}
// will generate
@media all and (min-width: 500px) and (max-width: 1000px) {
...
}
How cool is that?
@ screen(min-width, max-width, orientation)
@ min-screen(width)
@ max-screen(width)
--
@ screen-height(min-height, max-height, orientation)
@ min-screen-height(height)
@ max-screen-height(height)
--
@ hdpi(ratio)
--
@ landscape
@ portrait
--
@ iphone4(orientation)
@ iphone5(orientation)
@ iphone6(orientation)
@ iphone6-plus(orientation)
--
@ ipad(orientation)
@ ipad-retina(orientation)
--
@ hdtv(standard)
It targets group of devices or just one with particular screen width and orientation (optional).
@include screen(320px, 640px) { ... }
@include screen(768px, 1024px, landscape) { ... }
It will be compiled to:
@media screen and (min-width: 768px) and (max-width: 1280px) { ... }
@media screen and (min-width: 320px) and (max-width: 640px) and (orientation: landscape) { ... }
It's a shortcut for @media screen and (min-width ... )
@include min-screen(768px) { ... }
@include min-screen(1024px) { ... }
It will be compiled to:
@media screen and (min-width: 768px) { ... }
@media screen and (min-width: 1024px) { ... }
It's a shortcut for @media screen and (max-width ... )
@include max-screen(1024px) { ... }
@include max-screen(768px) { ... }
It will be compiled to:
@media screen and (max-width: 1024px) { ... }
@media screen and (max-width: 768px) { ... }
It targets group of devices or just one with particular screen height and orientation (optional).
@include screen-height(640px, 768px) { ... }
@include screen-height(640px, 768px, landscape) { ... }
It will be compiled to:
@media screen and (min-height: 768px) and (max-height: 1280px) { ... }
@media screen and (min-height: 768px) and (max-height: 1280px) and (orientation: landscape) { ... }
It's a shortcut for @media screen and (min-height ... )
@include min-screen-height(768px) { ... }
@include min-screen-height(1024px) { ... }
It will be compiled to:
@media screen and (min-height: 768px) { ... }
@media screen and (min-height: 1024px) { ... }
It's a shortcut for @media screen and (max-height ... )
@include max-screen-height(1024px) { ... }
@include max-screen-height(768px) { ... }
It will be compiled to:
@media screen and (max-height: 1024px) { ... }
@media screen and (max-height: 768px) { ... }
It targets devices with hdpi display.
.brand {
background-image: url(logo.png);
@include hdpi {
background-image: url(logo_2x.png);
}
}
Both mixins target different screen orientations.
@include landscape { ... }
@include portrait { ... }
It will be compiled to:
@media screen and (orientation: landscape) { ... }
@media screen and (orientation: portrait) { ... }
$orientation: all | portrait | landscape
It targets only iPhone 4 + orientation
It targets only iPhone 5 + orientation
It targets only iPhone 6 + orientation
It targets only iPhone 6 Plus + orientation
It targets all iPads + orientation
It targets only iPads with retina display + orientation
@include ipad { ... } // all iPads
@include ipad-retina { ... } // only iPad with retina
@include iphone5 { ... } // only iPhone 5
@include iphone4 { ... } // only iPhone 4/4S
// common part for iPhone 5 - landscape & portrait
@include iphone5 { ... }
@include iphone5(landscape) { ... }
@include iphone5(portrait) { ... }
$standard: '720p' | '1080' | '2K' | '4K'
It targets TVs with particular standard like 1080
or 4K
.title {
font-size: 5vm;
@include hdtv {
font-size: 10vm;
}
@include hdtv('4K') {
font-size: 15vm;
}
}
Feel free to check my website or follow me on twitter.
The MIT license
Copyright © 2015 Rafal Bromirski
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.