Last active
December 16, 2022 15:42
-
-
Save Asraf2asif/a1b8f1101c73cc4109f139ebba1636da to your computer and use it in GitHub Desktop.
My custom SCSS prefixer mixins collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@mixin size($width-param, $height-param:0) { | |
width: $width-param; | |
@if $height-param !=0 { | |
height: $height-param; | |
} | |
@else { | |
height: $width-param; | |
} | |
} | |
@mixin flex-center() { | |
@include display-flex-init(); | |
@include justify-content(center); | |
@include align-items(center); | |
} | |
@mixin pad-x($value) { | |
padding-left: $value; | |
padding-right: $value; | |
} | |
@mixin margin-x($value) { | |
margin-left: $value; | |
margin-right: $value; | |
} | |
@mixin center-x-absolute() { | |
left: 50%; | |
@include transform(translateX(-50%)); | |
} | |
@mixin center-y-absolute() { | |
top: 50%; | |
@include transform(translateY(-50%)); | |
} | |
@mixin flex-start() { | |
@include display-flex(); | |
@include justify-content(flex-start); | |
@include align-items(flex-start); | |
} | |
@mixin flex-end() { | |
@include display-flex(); | |
@include justify-content(flex-end); | |
@include align-items(flex-end); | |
} | |
@mixin display-flex($flex:0, $display:true, $justify-content:0, $align-items:0, $align-content:0, $placement:0, $direction:0, $wrap:0) { | |
@if $flex !=0 { | |
@include flex($flex); | |
} | |
@if $display==true { | |
@include display-flex-init(); | |
} | |
@if $justify-content !=0 { | |
@include justify-content($justify-content); | |
} | |
@if $align-items !=0 { | |
@include align-items($align-items); | |
} | |
@if $align-content !=0 { | |
@include align-content($align-content); | |
} | |
@if $placement==start { | |
@include justify-content(flex-start); | |
@include align-items(flex-start); | |
} | |
@else if $placement==end { | |
@include justify-content(flex-end); | |
@include align-items(flex-end); | |
} | |
@else if $placement==center { | |
@include justify-content(center); | |
@include align-items(center); | |
} | |
@if $direction !=0 { | |
@include flex-direction($direction); | |
} | |
@if $wrap !=0 { | |
@include flex-wrap($wrap); | |
} | |
} | |
@mixin pos-abs($top:false, $right:false, $bottom:false, $h:false, $v:false, $all:false, $left:false, $abs:true) { | |
@if $abs==true { | |
position: absolute; | |
} | |
@if $top !=false { | |
top: $top; | |
} | |
@if $right !=false { | |
right: $right; | |
} | |
@if $bottom !=false { | |
bottom: $bottom; | |
} | |
@if $left !=false { | |
left: $left; | |
} | |
@if $h !=false { | |
left: $h; | |
right: $h; | |
} | |
@if $v !=false { | |
top: $v; | |
bottom: $v; | |
} | |
@if $all !=false { | |
top: $all; | |
right: $all; | |
bottom: $all; | |
left: $all; | |
} | |
} | |
@mixin space-reset() { | |
margin: 0; | |
padding: 0; | |
} | |
@mixin media-break ($break-point, $device-type: max, $break-type: width, $media-type: screen) { | |
$break-logic: $device-type+'-'+$break-type; | |
@media #{$media-type} and (#{$break-logic}: $break-point) { | |
@content; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Mixin to prefix several properties at once | |
/// @author Kitty Giraudel | |
/// @param {Map} $declarations - Declarations to prefix | |
/// @param {List} $prefixes (()) - List of prefixes to print | |
@mixin prefix($declarations, $prefixes: (), $important: 0) { | |
@each $property, | |
$value in $declarations { | |
@each $prefix in $prefixes { | |
@if $important==1 { | |
#{'-' + $prefix + '-' + $property}: #{$value + '!important'}; | |
} | |
@else { | |
#{'-' + $prefix + '-' + $property}: $value; | |
} | |
} | |
// Output standard non-prefixed declaration | |
@if $important==1 { | |
#{$property}: #{$value + '!important'}; | |
} | |
@else { | |
#{$property}: $value; | |
} | |
} | |
} | |
@mixin prefix-value($declarations, $prefixes: (), $important: 0) { | |
@each $property, | |
$value in $declarations { | |
@each $prefix in $prefixes { | |
@if $important==1 { | |
#{$property}: #{'-' + $prefix + '-' + $value + '!important'}; | |
} | |
@else { | |
#{$property}: #{'-' + $prefix + '-' + $value}; | |
} | |
} | |
// Output standard non-prefixed declaration | |
@if $important==1 { | |
#{$property}: #{$value + '!important'}; | |
} | |
@else { | |
#{$property}: $value; | |
} | |
} | |
} | |
/// Mixins | |
/// @author Andy Crone | @andycrone_ | |
/// + Popular mixins including vendor prefixes for cross-browser support | |
/* | |
align-content | |
align-items | |
align-self | |
animation | |
animation-delay | |
appearance | |
backdrop-filter | |
background-size | |
border-radius | |
box-shadow | |
box-sizing | |
calc | |
display-flex | |
filter | |
flex | |
flex-direction | |
flex-wrap | |
justify-content | |
keyframes | |
linear-gradient | |
object-fit | |
transform | |
transform-origin | |
transition | |
user-select | |
word-break | |
*/ | |
@mixin align-content($value, $important: 0) { | |
-ms-flex-line-pack: center; | |
@include prefix((align-content: $value), webkit, $important); | |
} | |
@mixin align-items($value, $important: 0) { | |
-ms-flex-align: $value; | |
-webkit-box-align: $value; | |
-moz-box-align: $value; | |
@include prefix((align-items: $value), webkit, $important); | |
} | |
@mixin align-self($value, $important: 0) { | |
-ms-flex-item-align: $value; | |
-ms-grid-row-align: $value; | |
@include prefix((align-self: $value), webkit, $important); | |
} | |
@mixin animation($value, $important: 0) { | |
@include prefix((animation: $value), webkit moz ms o, $important); | |
} | |
@mixin animation-delay($value, $important: 0) { | |
@include prefix((animation-delay: $value), webkit moz o, $important); | |
} | |
@mixin appearance($value, $important: 0) { | |
@include prefix((appearance: $value), webkit mozv, $important); | |
} | |
@mixin backdrop-filter($value, $important: 0) { | |
@include prefix((backdrop-filter: $value), webkit, $important); | |
} | |
@mixin background-size($value, $important: 0) { | |
@include prefix((background-size: $value), webkit moz o, $important); | |
} | |
@mixin border-radius($value, $important: 0) { | |
@include prefix((border-radius: $value), webkit moz, $important); | |
} | |
@mixin box-shadow($value, $important: 0) { | |
@include prefix((box-shadow: $value), webkit moz, $important); | |
} | |
@mixin box-sizing($value, $important: 0) { | |
@include prefix((box-sizing: $value), webkit moz, $important); | |
} | |
@mixin calc($tag, $value, $important: 0) { | |
@include prefix-value(($tag: $value), webkit ms, $important); | |
} | |
@mixin display-flex-init($important: 0) { | |
display: -webkit-box; | |
display: -moz-box; | |
display: -ms-flexbox; | |
@include prefix-value((display: flex), webkit, $important); | |
} | |
@mixin filter($value, $important: 0) { | |
@include prefix((filter: $value), webkit moz ms o, $important); | |
} | |
@mixin flex($value, $important: 0) { | |
-webkit-box-flex: $value; | |
-moz-box-flex: $value; | |
@include prefix((flex: $value), webkit ms, $important); | |
} | |
@mixin flex-direction($value, $important: 0) { | |
-webkit-box-orient: vertical; | |
-webkit-box-direction: normal; | |
-moz-box-orient: vertical; | |
-moz-box-direction: normal; | |
@include prefix((flex-direction: $value), webkit ms, $important); | |
} | |
@mixin flex-wrap($value: wrap, $important: 0) { | |
@include prefix((flex-wrap: $value), webkit ms, $important); | |
} | |
@mixin justify-content($value, $important: 0) { | |
-webkit-box-pack: $value; | |
-moz-box-pack: $value; | |
-ms-flex-pack: $value; | |
@include prefix((justify-content: $value), webkit, $important); | |
} | |
@mixin keyframes($value) { | |
@-webkit-keyframes #{$value} { | |
@content; | |
} | |
@-moz-keyframes #{$value} { | |
@content; | |
} | |
@-o-keyframes #{$value} { | |
@content; | |
} | |
@keyframes #{$value} { | |
@content; | |
} | |
} | |
@mixin linear-gradient($angle, $gradient1, $gradient2) { | |
background-color: $gradient2; | |
/* Fallback Color */ | |
background-image: -webkit-gradient(linear, $angle, from($gradient1), to($gradient2)); | |
/* Saf4+, Chrome */ | |
/* Chrome 10+, Saf5.1+, iOS 5+ */ | |
/* FF3.6 */ | |
/* IE10 */ | |
/* Opera 11.10+ */ | |
@include prefix-value((background-image: linear-gradient($angle, $gradient1, $gradient2)), webkit moz ms o); | |
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=$angle, StartColorStr='#{$gradient1}', EndColorStr='#{$gradient2}'); | |
} | |
@mixin object-fit($value, $important: 0) { | |
@include prefix((object-fit: $value), o, $important); | |
} | |
@mixin transform($value, $important: 0) { | |
@include prefix((transform: $value), webkit moz ms o, $important); | |
} | |
@mixin transform-origin($value, $important: 0) { | |
@include prefix((transform-origin: $value), webkit moz ms o, $important); | |
} | |
@mixin transition($value, $important: 0) { | |
-webkit-transition: #{'-webkit-'+ $value}; | |
transition: #{'-webkit-'+ $value}; | |
transition: #{$value + ', '+ '-webkit-'+ $value}; | |
@include prefix((transition: $value), webkit moz o, $important); | |
} | |
@mixin user-select($value, $important: 0) { | |
-webkit-touch-callout: $value; | |
@include prefix((user-select: $value), webkit khtml moz ms, $important); | |
} | |
@mixin word-break($value, $important: 0) { | |
@include prefix((word-break: $value), ms, $important); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment