So, a beveled corner, a corner cut out of a box. So simple, yet so complex. With
these three Sass mixins doing them is quit easy.
Here’s some requirements we want our mixins to fill:
corner-bevel-veryold() works in IE8* corner-bevel-old() works in IE9*
corner-bevel-new() works in IE10* The beveled box needs to act like a normal
div (it almost does)* No extra elements* No JS, images, Data URIs or other
crap* Can be used against a multicoloured background* As easy to use as
border-radius
The corner-bevel-veryold() mixin
This supports IE8, the horizontal margins a bit wacky but it does the job if you
really need to support that.
Margins are a bit funny. You have to add the bevel height to it
Can't have border around the box
In IE8, you can't have margin in the last child element, use padding (see
image below). Ironically, IE8 doesn't support :last-child pseudo class
You can't have top right bevel being 20px and top left being 10px, all
bevels need to be the same amount (what you can do is to turn off each bevel)
The corner-bevel-old() mixin
This works pretty much the same as the before mentioned mixin. Difference being
that you don't need to mess with the margins, the element height includes the
bevels. It works down to IE9.
.module { @include corner-bevel(); // Apply padding and other styling to your liking padding: 0 20px;}
Limitations
Can't have border around the box
You can't have top right bevel being 20px and top left being 10px, all
bevels need to be the same amount (what you can do is to turn off each bevel)
The corner-bevel-new() mixin
This is the best and shortest of these, downside being it uses the CSS
gradients, that are not super widely supported. This technique was invented by
Lea Verou.
The logic is thus:
Demo
Configurable arguments
@mixin corner-bevel-new( $background-color: #aaa, // Background color, default `#aaa $corner-top-left-bevel: 10px, // Top left corner bevel amount $corner-top-right-bevel: 10px, // Top right bevel amount bevel amount $corner-bottom-right-bevel: 10px, // Bottom right corner bevel amount $corner-bottom-left-bevel: 10px // Bottom left corner bevel amount);