Flexible Cover SCSS Mixin

Flexible version of the coverer mixin by Chris Coyier to make a child element cover it's closest relative parent – but with the option to add individual offsets using a "padding-shorthand-syntax" (top, right-left, bottom)... and it takes keywords too :-)

Use examples

// T R B L // -------------------- .cover { @include cover(); } // 0 0 0 0 .cover { @include cover(10px); } // 10px 10px 10px 10px .cover { @include cover(10px, 20px); } // 10px 20px 10px 20px .cover { @include cover(10px, 20px, 30px); } // 10px 20px 30px 20px .cover { @include cover(10px, 20px, 30px, 40px); } // 10px 20px 30px 40px .cover { @include cover($bottom: 30px); } // 0 0 30px 0 .cover { @include cover(10px, $bottom: 30px); } // 10px 10px 30px 10px

The mixin

@mixin cover($arglist... /* $top, $right, $bottom, $left */){ $map: keywords($arglist); top : map-get($map, top) or nth-or-null($arglist, 1) or 0; right : map-get($map, right) or nth-or-null($arglist, 2) or nth-or-null($arglist, 1) or 0; bottom : map-get($map, bottom) or nth-or-null($arglist, 3) or nth-or-null($arglist, 1) or 0; left : map-get($map, left) or nth-or-null($arglist, 4) or nth-or-null($arglist, 2) or nth-or-null($arglist, 1) or 0; position: absolute; } // Helper function // Return null rather than throwing an error if index is outside list range. @function nth-or-null($list, $index) { @return if(length($list) >= $index, nth($list, $index), null); }