Skip to content

Instantly share code, notes, and snippets.

@aydgn
Last active June 18, 2021 19:50
Show Gist options
  • Select an option

  • Save aydgn/7a9d6dd450632d85b11e54dab10e0dcd to your computer and use it in GitHub Desktop.

Select an option

Save aydgn/7a9d6dd450632d85b11e54dab10e0dcd to your computer and use it in GitHub Desktop.
Mobile first SCSS media query mixin
$breakpoints: (
"phone": 400px,
"phone-wide": 480px,
"phablet": 560px,
"tablet-small": 640px,
"tablet": 768px,
"tablet-wide": 1024px,
"desktop": 1248px,
"desktop-wide": 1440px);
@mixin mq($width, $type: min) {
@if map_has_key($breakpoints, $width) {
$width: map_get($breakpoints, $width);
@if $type==max {
$width: $width - 1px;
}
@media only screen and (#{$type}-width: $width) {
@content;
}
}
}
@aydgn
Copy link
Author

aydgn commented Jun 18, 2021

Usage

header {
  background-color: red;
  align-items: center;

  @include mq(tablet) {
    background-color: yellow;
  }

  @include mq(desktop) {
    background-color: darkblue;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment