How to use media qurey mixin in SASS

media-breakpoint-between($lower, $upper)

Dependencies

The mixins are declared in mixins/_breakpoints.scss, and depend on the $grid-breakpoints map, found in _variables.scss.

Example

Breakpoint map:

$grid-breakpoints: (
  xs: 0,
  sm: 576px,
  md: 768px,
  lg: 992px,
  xl: 1200px
) 

Mixin:

@include media-breakpoint-between(sm, md) {
    // your code
}

Compiles to

@media (min-width: 576px) and (max-width: 991px) {}

Important notice

Media-breakpoint-between mixin uses ‘lower’ and ‘upper’ values of declared breakpoint.

  • The ‘lower’ value of breakpoint is the declared value in $grid-breakpoint map.
  • The ‘upper’ value of specific breakpoint is equal to the value of higher breakpoint minus 1px.

Upper & lower breakpoint values example (based od $grid-breakpoint map)

Lower value of md is equal to 576
Upper value of md is equal to 991 ( value of next breakpoint (lg) minus 1px (992px-1px)

Other media mixins

@include media-breakpoint-up(sm) {} creates a breakpoint with a min-width of $sm.

@include media-breakpoint-down(md) {} creates a breakpoint with a max-width of $md.

Published by anthonykuong

Anthony is a versatile Software professional with around 10 years of experience. He is a Full Stack developer experienced with clients in the Financial, Health and Supply Chain industries. He is experienced with MVC frameworks ( Spring Boot) , SPA frameworks ( Angular , VueJS), and also supports automated build deployments and packaging for development, qa, and production servers.. He has delivered rich user experience using Modern web technologies and techniques such are HTML5, CSS3, ECMAScript 6 (ES6)/ ECMAScript 2015, CSS pre-processors (SASS, Less), JavaScript build tools (Grunt, Gulp) , various UI Frameworks including AngularJS , Knockout JS , and CSS Frameworks including Bootstrap, and Foundation. He is adaptable to new technologies and frameworks. He is a rigorous, quality-conscious contributor with solid analytical skills. I can also be found on youtube - Youtube Channel: https://www.youtube.com/user/akuong/

Leave a comment