Colección de los 10 mixins de SASS que más vengo utilizando en la mayoría de proyectos con su correspondiente ejemplo de uso en scss:

1. Media Queries

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$mobile: 480px;
$tabletPortrait: 767px;
$tabletLandscape: 1024px;
$desktop: 1200px;
@mixin breakpoint($media) {
@if $media == mobile {
@media (max-width: $mobile) { @content; }
}
@else if $media == tablet {
@media (min-width: $tabletPortrait) and (max-width: $tabletLandscape) { @content; }
}
@else if $media == smallScreen {
@media (max-width: $desktop) { @content; }
}
@else if $media == desktop {
@media (min-width: $desktop) { @content; }
}
}
$mobile: 480px; $tabletPortrait: 767px; $tabletLandscape: 1024px; $desktop: 1200px; @mixin breakpoint($media) { @if $media == mobile { @media (max-width: $mobile) { @content; } } @else if $media == tablet { @media (min-width: $tabletPortrait) and (max-width: $tabletLandscape) { @content; } } @else if $media == smallScreen { @media (max-width: $desktop) { @content; } } @else if $media == desktop { @media (min-width: $desktop) { @content; } } }
$mobile: 480px;
$tabletPortrait: 767px;
$tabletLandscape: 1024px;
$desktop: 1200px;

@mixin breakpoint($media) {
  @if $media == mobile {
    @media (max-width: $mobile) { @content; }
  }
  @else if $media == tablet {
    @media (min-width: $tabletPortrait) and (max-width: $tabletLandscape) { @content; }
  }
  @else if $media == smallScreen {
    @media (max-width: $desktop) { @content; }
  }
  @else if $media == desktop {
    @media (min-width: $desktop) { @content; }
  }
}

Uso:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
aside {
width: 30%;
float: right;
@include breakpoint(mobile) {
width: 100%;
float: none;
}
}
aside { width: 30%; float: right; @include breakpoint(mobile) { width: 100%; float: none; } }
aside {
  width: 30%;
  float: right;
  @include breakpoint(mobile) {
    width: 100%;
    float: none;
  }
}

2. Transitions

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@mixin transition($what: all, $length: .3s, $easing: ease-in-out, $args: '') {
@if( $args=='' ){
-webkit-transition: $what $length $easing;
transition: $what $length $easing;
} @else {
-webkit-transition: $args;
transition: $args;
}
}
@mixin transition($what: all, $length: .3s, $easing: ease-in-out, $args: '') { @if( $args=='' ){ -webkit-transition: $what $length $easing; transition: $what $length $easing; } @else { -webkit-transition: $args; transition: $args; } }
@mixin transition($what: all, $length: .3s, $easing: ease-in-out, $args: '') {
  @if( $args=='' ){
    -webkit-transition: $what $length $easing;
    transition: $what $length $easing;
  } @else {
    -webkit-transition: $args;
    transition: $args;
  }
}

Uso:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
.elemento {
@include transition;
}
a {
@include transition(color);
}
.elemento { @include transition; } a { @include transition(color); }
.elemento {
  @include transition;
}
a {
  @include transition(color);
}

3. Transform

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@mixin transform($args){
-webkit-transform: $args;
transform: $args;
}
@mixin transform($args){ -webkit-transform: $args; transform: $args; }
@mixin transform($args){
  -webkit-transform: $args;
  transform: $args;
}

Uso:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
.elemento {
@include transform(rotate(45deg));
}
.elemento { @include transform(rotate(45deg)); }
.elemento {
  @include transform(rotate(45deg));
}

4. Clearfix

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
%clearfix {
&:before,
&:after {
content: "";
display: table;
}
&:after {
clear: both;
}
}
%clearfix { &:before, &:after { content: ""; display: table; } &:after { clear: both; } }
%clearfix {
  &:before,
  &:after {
    content: "";
    display: table;
  }
  &:after {
    clear: both;
  }
}

Uso:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
.elemento {
@extend %clearfix;
}
.elemento { @extend %clearfix; }
.elemento {
  @extend %clearfix;
}

5. Keyframes

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@mixin keyframes($name) {
@-webkit-keyframes #{$name} {
@content;
}
@keyframes #{$name} {
@content;
}
}
@mixin keyframes($name) { @-webkit-keyframes #{$name} { @content; } @keyframes #{$name} { @content; } }
@mixin keyframes($name) {
  @-webkit-keyframes #{$name} {
    @content;
  }
  @keyframes #{$name} {
    @content;
  }
}

Uso:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@include keyframes(nombre-animacion) {
0% { opacity: 0.3; }
50% { opacity: 1; }
100% { opacity: 0.3; }
}
@include keyframes(nombre-animacion) { 0% { opacity: 0.3; } 50% { opacity: 1; } 100% { opacity: 0.3; } }
@include keyframes(nombre-animacion) {
  0%   { opacity: 0.3; }
  50%  { opacity: 1; }
  100% { opacity: 0.3; }
}

6. Liner-Gradients

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@mixin linear-gradient($fromColor, $toColor) {
background-color: $toColor;
background-image: -webkit-gradient(linear, left top, left bottom, from($fromColor), to($toColor));
background-image: -webkit-linear-gradient(top, $fromColor, $toColor);
background-image: linear-gradient(top, $fromColor, $toColor);
}
@mixin linear-gradient($fromColor, $toColor) { background-color: $toColor; background-image: -webkit-gradient(linear, left top, left bottom, from($fromColor), to($toColor)); background-image: -webkit-linear-gradient(top, $fromColor, $toColor); background-image: linear-gradient(top, $fromColor, $toColor); }
@mixin linear-gradient($fromColor, $toColor) {
  background-color: $toColor;
  background-image: -webkit-gradient(linear, left top, left bottom, from($fromColor), to($toColor));
  background-image: -webkit-linear-gradient(top, $fromColor, $toColor);
  background-image: linear-gradient(top, $fromColor, $toColor);
}

Uso:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
.elemento {
@include linear-gradient(#000,#fff);
}
.elemento { @include linear-gradient(#000,#fff); }
.elemento {
  @include linear-gradient(#000,#fff);
}

7. Box-Sizing

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@mixin box-sizing($args : border-box){
-webkit-box-sizing: $args;
-moz-box-sizing: $args;
box-sizing: $args;
}
@mixin box-sizing($args : border-box){ -webkit-box-sizing: $args; -moz-box-sizing: $args; box-sizing: $args; }
@mixin box-sizing($args : border-box){
  -webkit-box-sizing: $args;
  -moz-box-sizing: $args;
  box-sizing: $args;
}

Uso:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
.elemento {
@include box-sizing;
}
.elemento { @include box-sizing; }
.elemento {
  @include box-sizing;
}

8. Text Overflow

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@mixin text-truncate {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
@mixin text-truncate { text-overflow: ellipsis; white-space: nowrap; overflow: hidden; }
@mixin text-truncate {
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

Uso:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
.elemento {
@include text-truncate;
}
.elemento { @include text-truncate; }
.elemento {
  @include text-truncate;
}

9. Hide

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@mixin hide {
display:block;
text-indent:-666px;
overflow: hidden;
}
@mixin hide { display:block; text-indent:-666px; overflow: hidden; }
@mixin hide {
  display:block;
  text-indent:-666px;
  overflow: hidden;
}

Uso:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
.elemento {
@include hide;
}
.elemento { @include hide; }
.elemento {
  @include hide;
}

10. Font-size Rem

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@function countRem($value) {
$remValue: $value / 16px;
@return $remValue * 1rem;
}
@mixin font-size($value) {
font-size: $value;
font-size: calculateRem($value);
}
@function countRem($value) { $remValue: $value / 16px; @return $remValue * 1rem; } @mixin font-size($value) { font-size: $value; font-size: calculateRem($value); }
@function countRem($value) {
  $remValue: $value / 16px;
  @return $remValue * 1rem;
}
@mixin font-size($value) {
  font-size: $value;
  font-size: calculateRem($value);
}

Uso:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
.elemento {
@include font-size(24px); }
}
.elemento { @include font-size(24px); } }
.elemento {
  @include font-size(24px); }
}

Agradezco tu comentario 🤘