Skip to content

Instantly share code, notes, and snippets.

@NitsanBaleli
Created March 27, 2018 10:24
Show Gist options
  • Select an option

  • Save NitsanBaleli/6b435651ecaf701441bb630f2ae30253 to your computer and use it in GitHub Desktop.

Select an option

Save NitsanBaleli/6b435651ecaf701441bb630f2ae30253 to your computer and use it in GitHub Desktop.
css triangle
@mixin equilateral-triangle($direction, $size, $color) {
width: 0;
height: 0;
@if $direction == 'up' {
border-left: em($size) solid transparent;
border-right: em($size) solid transparent;
border-bottom: em($size) solid $color;
}
@else if $direction == 'down' {
border-left: em($size) solid transparent;
border-right: em($size) solid transparent;
border-top: em($size) solid $color;
}
@else if $direction == 'right' {
border-top: em($size) solid transparent;
border-bottom: em($size) solid transparent;
border-left: em($size) solid $color;
}
@else if $direction == 'left' {
border-top: em($size) solid transparent;
border-bottom: em($size) solid transparent;
border-right: em($size) solid $color;
}
}
@function em($pixels, $context: 16px) {
@return #{$pixels/$context}em;
}
.test {
margin-top: 100px;
height: 50px;
width: 50px;
border: 1px solid black;
position: relative;
&::before {
content: "";
position: absolute;
top: 0;
transform: translateY(-100%) rotate(45deg); @include equilateral-triangle(up, 5px, red); } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment