Scss Query
Simple and memorizeable @media
queries helper function; build query strings defining a mode and a breakpoint name.
Example:
// Set custom breakpoints ; // @import query function // Profit
Protip: Use @include query(init, $query-breakpoints)
to (re)initialize query()
function whenever you want. Refer to the API for an overview of all the available runtime manipulation mixins.
Installation
The recommended installation method is Bower but you can manually install query()
function as well.
Install using Bower
$ bower install --save scss-query
Install via file download
You can always just download this repository into your project and @import
it.
Usage
The initial example should cover pretty much everything there is to know for basic usage. But let's quick-start you even more:
Bootstrap
with// v4 ; // v3 ;
Foundation
with// v6 ;
query(
mode
,
size
)
Function mode
Parameter Mode can be one of the following:
min
- Min breakpointsmax
- Max breakpointsonly
- Min and max breakpoints
In case mode is max
or only
1px will be substracted from max breakpoint value to prevent conflicting breakpoints. If breakpoint value is not in pixels, conversion will be handled trough a function named after breakpoint value unit – for em
there is a fallback integrated.
If mode is only
, max size will be next breakpoint in context.
size
Parameter Key in $query-breakpoints
.
query()
function ships with a list of common screen sizes as default breakpoints. These are just for a quick start and it is recommended to change them to fit your design.
Defaults
Defaults are in pixels. However, if you want to use another value like em
you can do that too. Remember to set $query-breakpoints
before importing query()
function in order to overwrite the defaults.
;
API
The API allows for runtime manipulation of query()
context. The following methods are provided as mixin via @include query($method, $args...)
:
Method | Description |
---|---|
add |
Add a new breakpoint |
remove |
Remove an existing breakpoint |
set |
Set one or multible existing breakpoints at once |
reset |
Reset context (aka remove all breakpoints) |
init |
Initialise query function by passing a map |
use |
Use a breakpoint while in mixin's @content |
See query/_api.scss for documentation on the individual mixins.
Contributing
As an open-source project, contributions are more than welcome, they're extremely helpful and actively encouraged. In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt. If you see any room for improvement, open an issue or submit a pull request.
License
This project is provided under the terms of the MIT License.
Authored by Nicolas Müller Noulezas · Github · Twitter · CodePen