Skip to content

Instantly share code, notes, and snippets.

@charlieschwabacher
Created July 21, 2011 07:41
Show Gist options
  • Star 43 You must be signed in to star a gist
  • Fork 20 You must be signed in to fork a gist
  • Save charlieschwabacher/1096739 to your computer and use it in GitHub Desktop.
Save charlieschwabacher/1096739 to your computer and use it in GitHub Desktop.
SCSS mixins for cross browser CSS3 border-radius, transition, gradient, and box shadow
//Cross browser CSS3 mixins
@mixin box-shadow($left, $top, $radius, $color) {
box-shadow: $left $top $radius $color;
-webkit-box-shadow: $left $top $radius $color;
-moz-box-shadow: $left $top $radius $color;
}
@mixin transition($property, $duration, $easing: linear) {
transition: $property $duration $easing;
-webkit-transition: $property $duration $easing;
-moz-transition: $property $duration $easing;
}
@mixin border-radius($radius) {
border-radius: $radius;
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
}
@mixin border-radii($topleft, $topright, $bottomright, $bottomleft) {
border-top-left-radius: $topleft;
border-top-right-radius: $topright;
border-bottom-right-radius: $bottomright;
border-bottom-left-radius: $bottomleft;
-webkit-border-top-left-radius: $topleft;
-webkit-border-top-right-radius: $topright;
-webkit-border-bottom-right-radius: $bottomright;
-webkit-border-bottom-left-radius: $bottomleft;
-moz-border-radius-topleft: $topleft;
-moz-border-radius-topright: $topright;
-moz-border-radius-bottomright: $bottomright;
-moz-border-radius-bottomleft: $bottomleft;
}
@mixin gradient($color1, $color2) {
background-color: $color1;
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr=#{$color1}, endColorstr=#{$color2});
background-image: -moz-linear-gradient(center top, $color1, $color2);
background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from($color1), to($color2));
}
@charlieschwabacher
Copy link
Author

Surprisingly, I couldn't find anything like this on Google. Hopefully this will save someone a little time.

@jbbarth
Copy link

jbbarth commented Aug 26, 2011

Was useful for me at least, thanks!

@r01010010
Copy link

Thank you, this saves a lot

@everaldomatias
Copy link

everaldomatias commented Jan 23, 2018

Very great. Thanks.

For placeholder i found it: https://gist.github.com/mturnwall/9e055b89b374bb429947

@mervick
Copy link

mervick commented Sep 4, 2018

@mixin border-radii($topleft: null, $topright: null, $bottomright: null, $bottomleft: null) {
  @if $topleft != null and $topleft >= 0 {
    border-top-left-radius: $topleft;;
    -webkit-border-top-left-radius: $topleft;
    -moz-border-radius-topleft: $topleft;
  }

  @if $topright != null and $topright >= 0 {
    border-top-right-radius: $topright;
    -webkit-border-top-right-radius: $topright;
    -moz-border-radius-topright: $topright;
  }

  @if $bottomleft != null and $bottomleft >= 0 {
    border-bottom-left-radius: $bottomleft;
    -webkit-border-bottom-left-radius: $bottomleft;
    -moz-border-radius-bottomleft: $bottomleft;
  }

  @if $bottomright != null and $bottomright >= 0 {
    border-bottom-right-radius: $bottomright;
    -webkit-border-bottom-right-radius: $bottomright;
    -moz-border-radius-bottomright: $bottomright;
  }
}

@Ajax30
Copy link

Ajax30 commented Jun 24, 2020

I used it like this: @include border-radii(0, 0, 5px, 5px);.
I get this error: Error: Mixin border-radii missing argument $topright..

Why does this happen?

@raashidA
Copy link

I used it like this: @include border-radii(0, 0, 5px, 5px);.
I get this error: Error: Mixin border-radii missing argument $topright..

Why does this happen?

You have to use "Null" instead of "0"

@krishhnaa
Copy link

krishhnaa commented Mar 16, 2022

@mixin border-radii($topleft: null, $topright: null, $bottomright: null, $bottomleft: null) {
  @if $topleft != null and $topleft >= 0 {
    border-top-left-radius: $topleft;;
    -webkit-border-top-left-radius: $topleft;
    -moz-border-radius-topleft: $topleft;
  }

  @if $topright != null and $topright >= 0 {
    border-top-right-radius: $topright;
    -webkit-border-top-right-radius: $topright;
    -moz-border-radius-topright: $topright;
  }

  @if $bottomleft != null and $bottomleft >= 0 {
    border-bottom-left-radius: $bottomleft;
    -webkit-border-bottom-left-radius: $bottomleft;
    -moz-border-radius-bottomleft: $bottomleft;
  }

  @if $bottomright != null and $bottomright >= 0 {
    border-bottom-right-radius: $bottomright;
    -webkit-border-bottom-right-radius: $bottomright;
    -moz-border-radius-bottomright: $bottomright;
  }
}

you can also do like this right?

@mixin border-radius($top-left:null, $top-right:null, $bottom-right:null, $bottom-left:null){
  -webkit-border-radius: $top-left $top-right $bottom-right $bottom-left;
  -moz-border-radius: $top-left $top-right $bottom-right $bottom-left;
  -ms-border-radius: $top-left $top-right $bottom-right $bottom-left;
  border-radius: $top-left $top-right $bottom-right $bottom-left;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment