Skip to content

Instantly share code, notes, and snippets.

@alxpsr
Created July 13, 2016 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alxpsr/ec103a6364c793b80d6ee58b15cc1b13 to your computer and use it in GitHub Desktop.
Save alxpsr/ec103a6364c793b80d6ee58b15cc1b13 to your computer and use it in GitHub Desktop.
shared-adaptive
$devices: tablet-landscape, tablet-portrait, tablet, phone, mobile, mobile-landscape, not-mobile !default;
$tablet-landscape: 1024px !default;
$tablet-portrait: 768px !default;
$phone: 480px !default;
@mixin device($device) {
//481...1024
@if $device == 'tablet' {
@media screen and (max-width: $tablet-landscape) and (min-width: $phone + 1) {
@content;
}
}
//0...768
@else if $device == 'mobile-landscape' {
@media screen and (max-width: $tablet-portrait) {
@content;
}
}
//769...1024
@else if $device == 'tablet-landscape' {
@media screen and (max-width: $tablet-landscape) and (min-width: $tablet-portrait + 1) {
@content;
}
}
//481...768
@else if $device == 'tablet-portrait' {
@media screen and (max-width: $tablet-portrait) and (min-width: $phone + 1) {
@content;
}
}
//0...480
@else if $device == 'phone' {
@media screen and (max-width: $phone) {
@content;
}
}
//0...1024
@else if $device == 'mobile' {
@media screen and (max-width: $tablet-landscape) {
@content;
}
}
//1025...+Infinity
@else if $device == 'not-mobile' {
@media screen and (min-width: $tablet-landscape + 1) {
@content;
}
}
@else if not index($devices, $device) {
@error 'Wrong argument';
}
}
//использовать только в крайних случаях
@mixin device-custom( $min, $max ) {
@if $min != 'none' and $max != 'none' {
@media screen and (min-width: $min) and (max-width: $max) {
@content;
}
}
@else if $min == 'none' {
@media screen and (max-width: $max) {
@content;
}
}
@else if $max == 'none' {
@media screen and (min-width: $min) {
@content;
}
}
@else if $min == null and $max == null {
@error 'Wrong arguments';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment