Skip to content

Instantly share code, notes, and snippets.

@encrypticus
Created September 1, 2019 14:37
Show Gist options
  • Select an option

  • Save encrypticus/d6d027fdd01dd6e8b9514d9e8025c2d7 to your computer and use it in GitHub Desktop.

Select an option

Save encrypticus/d6d027fdd01dd6e8b9514d9e8025c2d7 to your computer and use it in GitHub Desktop.
scss mixins
// Загружает шрифт
@mixin load-font($src: null, $family: san-serif, $style: normal, $weight: normal) {
@font-face {
font-family: $family;
font-style: $style;
font-weight: $weight;
@if ($src) {
src: url($src + '.woff') format('woff'),
url($src + '.ttf') format('truetype'),
url($src + '.svg') format('svg');
}
}
}
// Конвертирует размер шрифта из px в rem
@mixin fontSizeToRem($targetValue, $rootValue: 16) {
font-size: $targetValue / $rootValue + rem;
}
// Конвертирует размер указанного свойства из px в rem
@mixin pxToRem($propName, $targetValue, $rootValue: 16) {
#{$propName}: $targetValue / $rootValue + rem;
}
// Конвертирует размер указанного свойства из px в %
@mixin pxToPercent($propName, $targetValue, $parentValue) {
#{$propName}: $targetValue / $parentValue * 100%;
}
// Mobile breakpoints
@mixin for-small-phone-only() {
@media (max-width: 320px) {
@content;
}
}
@mixin for-middle-phone-only() {
@media (max-width: 360px) {
@content;
}
}
@mixin for-phone-only() {
@media (max-width: 480px) {
@content;
}
}
@mixin for-tablet-portrait-up() {
@media (min-width: 481px) {
@content;
}
}
@mixin for-tablet-landscape-up() {
@media (min-width: 769px) {
@content;
}
}
@mixin for-laptop-up() {
@media (min-width: 1025px) {
@content;
}
}
@mixin for-desktop-up() {
@media (min-width: 1281px) {
@content;
}
}
//Desktop brearpoints
@mixin for-desktop-down() {
@media (max-width: 1280px) {
@content;
}
}
@mixin for-laptop-down() {
@media (max-width: 1024px) {
@content;
}
}
@mixin for-tablet-landscape-down() {
@media (max-width: 768px) {
@content;
}
}
@mixin for-tablet-portrait-down() {
@media (max-width: 480px) {
@content;
}
}
@mixin for-phone-landscape-down() {
@media (max-width: 640px) and (orientation: landscape) {
@content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment