A Pen by Andrew Houle on CodePen.
Created
February 11, 2016 20:46
-
-
Save mkormendy/423a0e24cd4e3a3b8e5a to your computer and use it in GitHub Desktop.
SASS Triangle Mixin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="background"> | |
<div class="foo"> | |
<div class="bar"> | |
Look ma, a triangle! | |
</div> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@mixin triangle($direction, $size: 0.375rem, $color: #222){ | |
content: ''; | |
display: block; | |
position: absolute; | |
height: 0; width: 0; | |
@if ($direction == 'up'){ | |
border-bottom: $size solid $color; | |
border-left: $size solid transparent; | |
border-right: $size solid transparent; | |
} | |
@else if ($direction == 'down'){ | |
border-top: $size solid $color; | |
border-left: $size solid transparent; | |
border-right: $size solid transparent; | |
} | |
@else if ($direction == 'left'){ | |
border-top: $size solid transparent; | |
border-bottom: $size solid transparent; | |
border-right: $size solid $color; | |
} | |
@else if ($direction == 'right'){ | |
border-top: $size solid transparent; | |
border-bottom: $size solid transparent; | |
border-left: $size solid $color; | |
} | |
} | |
.background { | |
background: red; | |
width: 100%; | |
height: 100%; | |
position: absolute; | |
top: 0; | |
left: 0; | |
} | |
.foo { | |
position: absolute; | |
width: 50%; | |
height: 100px; | |
left: 50%; | |
top: 50%; | |
transform: translate(-50%,-50%); | |
background: blue; | |
&:after { | |
@include triangle(down, 10px, blue); | |
position: absolute; | |
bottom: -10px; | |
left: 50%; | |
margin-left: -12px; | |
} | |
} | |
.bar { | |
position: absolute; | |
left: 50%; | |
top: 50%; | |
transform: translate(-50%,-50%); | |
text-align: center; | |
color: #fff; | |
font-weight: bold; | |
font-family: helvetica, sans-serif; | |
font-size: 18px; | |
padding: 20px; | |
width: 100%; | |
box-sizing: border-box; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment