Skip to content

Instantly share code, notes, and snippets.

@mechaneyes
Last active September 1, 2024 09:10
Show Gist options
  • Save mechaneyes/58380f6f9ce983716f9274d757304ae9 to your computer and use it in GitHub Desktop.
Save mechaneyes/58380f6f9ce983716f9274d757304ae9 to your computer and use it in GitHub Desktop.
Media Queries, Breakpoints
// ————————————————————————————————————o usage —>
//
// // w/o orientation
// @include bp("medium") {
// .class {
// width: 100%;
// }
// }
// // portrait
// @include bp("medium", "portrait") {
// .class {
// width: 100%;
// }
// }
// // landscape
// @include bp("medium", "landscape") {
// .class {
// width: 100%;
// }
// }
$breakpoints: (
"640": 640px,
"768": 768px,
"1024": 1024px,
"1280": 1280px,
"1536": 1536px,
"xsmall": 320px,
"iphone": 493px,
"small": 480px,
"medium": 672px,
"large": 1056px,
"xlarge": 1312px,
"max": 1584px,
) !default;
/// Mixin to manage responsive breakpoints
/// Addapted from Kitty Giraudel
///
/// @param {String} $breakpoint - Breakpoint name
/// @param {String} $orientation - Optional orientation (portrait or landscape)
/// @require $breakpoints
@mixin bp($breakpoint, $orientation: null) {
// If the key exists in the map
@if map-has-key($breakpoints, $breakpoint) {
// Base media query
$media-query: "(min-width: #{map-get($breakpoints, $breakpoint)})";
// Add orientation if provided
@if $orientation == "portrait" {
$media-query: "#{$media-query} and (orientation: portrait)";
} @else if $orientation == "landscape" {
$media-query: "#{$media-query} and (orientation: landscape)";
}
// Apply the media query
@media #{$media-query} {
@content;
}
}
// If the key doesn't exist in the map
@else {
@warn "no value could be retrieved from `#{$breakpoint}`. "
+ "available breakpoints are: #{map-keys($breakpoints)}.";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment