|
// ---------------------------------------------------- |
|
// Media queries |
|
// ---------------------------------------------------- |
|
|
|
// Media queries allow you to easily add custom break |
|
// points to your stylesheets, and quickly add custom |
|
// responsive behavior within an element for different |
|
// break points. However, littering stylesheet media |
|
// queries can quickly become a cause for headaches, |
|
// especially when it comes to maintaining them down |
|
// the road. With Sass mixins, all that can change. |
|
|
|
// mixin |
|
// ---------------------------------------------------- |
|
|
|
// The if statement will emit a media query tuned to a |
|
// particular screen size depending on the size name |
|
// provided to the mixin. This will allow you to easily |
|
// adjust the behavior of your CSS attributes |
|
// accordingly. You can also customize the point in |
|
// which you want to adjust your CSS attributes. |
|
// Usually, the most responsive layouts will stick |
|
// with 3 or 4 defined screen width dimensions to |
|
// adjust the content to. The variance of screen sizes, |
|
// devices, and applications is always expanding, |
|
// but there is a popular trend many web developers |
|
// will use for their layouts; small screen sizes for |
|
// phones, medium for tablets, large for laptops, |
|
// and extra large for desktop computers. |
|
|
|
// Define the breakpoints |
|
$breakpoint-small: 600px; |
|
$breakpoint-med-small: 960px; |
|
$breakpoint-med: 1175px; |
|
|
|
@mixin screen($size, $type: max, $pixels: $breakpoint-small) { |
|
@if $size == 'small' { |
|
@media screen and ($type + -width: $breakpoint-small) { |
|
@content; |
|
} |
|
} |
|
@else if $size == 'med-small' { |
|
@media screen and ($type + -width: $breakpoint-med-small) { |
|
@content; |
|
} |
|
} |
|
@else if $size == 'med' { |
|
@media screen and ($type + -width: $breakpoint-med) { |
|
@content; |
|
} |
|
} |
|
@else if $size == 'large' { |
|
@media screen and ($type + -width: $breakpoint-med) { |
|
@content; |
|
} |
|
} |
|
@else if $size == 'custom' { |
|
@media screen and ($type + -width: $pixels + px) { |
|
@content; |
|
} |
|
} |
|
@else { |
|
@content; |
|
} |
|
} |
|
|
|
// use |
|
// ---------------------------------------------------- |
|
|
|
// Using the mixin |
|
.foo { |
|
@include screen(large) { |
|
width: 20%; |
|
} |
|
@include screen(med) { |
|
width: 40%; |
|
} |
|
@include screen(med-small) { |
|
width: 60%; |
|
} |
|
@include screen(small) { |
|
width: 80%; |
|
} |
|
@include screen(custom, max, 400) { |
|
width: 100%; |
|
} |
|
} |
|
|
|
|
|
// compiled CSS output |
|
// ---------------------------------------------------- |
|
|
|
|
|
// @media screen and (max-width: 1175px) { |
|
// .foo { |
|
// width: 20%; |
|
// } |
|
// } |
|
// @media screen and (max-width: 1175px) { |
|
// .foo { |
|
// width: 40%; |
|
// } |
|
// } |
|
// @media screen and (max-width: 960px) { |
|
// .foo { |
|
// width: 60%; |
|
// } |
|
// } |
|
// @media screen and (max-width: 600px) { |
|
// .foo { |
|
// width: 80%; |
|
// } |
|
// } |
|
// @media screen and (max-width: 400px) { |
|
// .foo { |
|
// width: 100%; |
|
// } |
|
// } |
|
|