Skip to content

Instantly share code, notes, and snippets.

@shiftgeist
Last active May 4, 2018 13:36
Show Gist options
  • Save shiftgeist/53d23975f88150e9bb9285b77497bb86 to your computer and use it in GitHub Desktop.
Save shiftgeist/53d23975f88150e9bb9285b77497bb86 to your computer and use it in GitHub Desktop.
Generate border-radius with all corners and general with Sass
.border-radius {
border-radius: 5px;
}
.border-radius-small {
border-radius: 3px;
}
.border-radius-small-top-left {
border-radius: 3px;
}
.border-radius-small-top-right {
border-radius: 3px;
}
.border-radius-small-bottom-left {
border-radius: 3px;
}
.border-radius-small-bottom-right {
border-radius: 3px;
}
.border-radius-medium {
border-radius: 5px;
}
.border-radius-medium-top-left {
border-radius: 5px;
}
.border-radius-medium-top-right {
border-radius: 5px;
}
.border-radius-medium-bottom-left {
border-radius: 5px;
}
.border-radius-medium-bottom-right {
border-radius: 5px;
}
.border-radius-large {
border-radius: 10px;
}
.border-radius-large-top-left {
border-radius: 10px;
}
.border-radius-large-top-right {
border-radius: 10px;
}
.border-radius-large-bottom-left {
border-radius: 10px;
}
.border-radius-large-bottom-right {
border-radius: 10px;
}
// Where the magic happends
$border-list: top-left top-right bottom-left bottom-right;
@mixin border-location($size, $size-unit) {
&-#{$size} {
border-radius: $size-unit;
@each $list-item in $border-list {
&-#{$list-item} {
border-radius: $size-unit;
}
}
}
}
.border-radius {
border-radius: 5px; //Default
@include border-location(small, 3px);
@include border-location(medium, 5px);
@include border-location(large, 10px);
}
<div class="border-radius-small">
<h1>Hello world</h1>
</div>

.border-radius-THESIZE-THELOCATION

THESIZE's: small, medium, large

THELOCATION's: top-left, top-right, bottom-left, bottom-right

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