Created
December 16, 2015 14:42
-
-
Save peterbraden/141b45f97c16759db0cb to your computer and use it in GitHub Desktop.
Tooltip sass mixin
This file contains 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='tooltip'> | |
Hello world | |
</div> | |
<div class='t2'> | |
Hello world | |
</div> |
This file contains 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
.tooltip { | |
width:200px; | |
@include ttip(1rem, right); | |
} | |
.t2 { | |
@include ttip(30px, left); | |
position:absolute; | |
right:10px; | |
width: 100px; | |
} |
This file contains 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 ttip($size, $direction) { | |
box-shadow: 1px 0px 3px #000; | |
padding: $size; | |
background-color: white; | |
position: relative; | |
&:before { | |
// Shadow | |
box-shadow: 1px 0px 3px #000; | |
content: " "; | |
width: $size; | |
height: $size; | |
background-color: white; | |
display: block; | |
position:absolute; | |
bottom: -0.5 * $size; | |
@if $direction == 'right' { | |
left: $size; | |
} @else { | |
right: $size; | |
} | |
transform: rotateZ(45deg); | |
} | |
&:after { | |
// Kill Shadow | |
content: " "; | |
width: 100%; | |
height: $size * 0.71; // 1 / sqrt 2 | |
background-color: white; | |
display: block; | |
position:absolute; | |
bottom:0; | |
left: 0; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://codepen.io/anon/pen/obbPMG?editors=110