Skip to content

Instantly share code, notes, and snippets.

@nfrette
Created June 2, 2015 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nfrette/099faa75c1a4f2fec658 to your computer and use it in GitHub Desktop.
Save nfrette/099faa75c1a4f2fec658 to your computer and use it in GitHub Desktop.
ToolTips
<div>
<a href="https://bitbucket.org/cbavota/css3-tips/" class="top-tip" data-tips="hover up top-tip">I'm a toltip</a>
</div>
div {
margin-top: 3rem;
}
//mixins
@mixin shadow ($x, $y, $z, $color) {
-moz-box-shadow: $x $y $z $color;
-webkit-box-shadow: $x $y $z $color;
box-shadow: $x $y $z $color;
}
@mixin transition ($position, $time, $timingFunction, $opacity, $duration, $durationFunction) {
-webkit-transition: $position $time $timingFunction, $opacity $duration $durationFunction;
-moz-transition: $position $time $timingFunction, $opacity $duration $durationFunction;
transition: $position $time $timingFunction, $opacity $duration $durationFunction;
}
.box-sizing {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
//variables
$fontSize: 12px;
$fontColor: #fff;
$backgroundColor: lighten(#3f618c, 25%);
$radius: 5px;
$colorShadow: rgba(0, 0, 0, 0.3);
$align: center;
$transitionDuration: .25s;
$transitionFunction: ease-in-out;
$transitionProperty: opacity;
[data-tips] {
position: relative;
text-decoration: none;
&:after,
&:before {
position: absolute;
z-index: 100;
opacity: 0;
}
&:after {
content: attr(data-tips);
height: 25px;
line-height: 25px;
padding: 0 10px;
font-size: $fontSize;
text-align: $align;
color: $fontColor;
background: $backgroundColor;
border-radius: 5px;
text-shadow: 0 0 5px #000;
white-space: nowrap;
@include shadow (0, 0, 5px, $colorShadow);
@extend .box-sizing;
}
&:before {
content: "";
width: 0;
height: 0;
border-width: 6px;
border-style: solid;
}
&:hover:after,
&:hover:before {
opacity: 1;
}
// Top tips
&.top-tip {
&:after,
&:before {
@include transition (bottom, $transitionDuration, $transitionFunction, $transitionProperty, $transitionDuration, $transitionFunction);
bottom: 90%;
left: -9999px;
margin-bottom: 12px;
}
&:before {
border-color: $backgroundColor transparent transparent transparent;
margin-bottom: 0;
}
&:hover:after,
&:hover:before {
bottom: 100%;
left: 0;
}
&:hover:before {
left: 15px;
}
}
// Bottom tip
&.bottom-tip {
&:after,
&:before {
@include transition (top, $transitionDuration, $transitionFunction, $transitionProperty, $transitionDuration, $transitionFunction);
top: 90%;
left: -9999px;
margin-top: 12px;
}
&:before {
border-color: transparent transparent $backgroundColor transparent;
margin-top: 0;
}
&:hover:after,
&:hover:before {
top: 100%;
left: 0;
}
&:hover:before {
left: 15px;
}
}
//Right tip
&.right-tip {
&:after,
&:before {
@include transition (left, $transitionDuration, $transitionFunction, $transitionProperty, $transitionDuration, $transitionFunction);
top: -9999px;
left: 96%;
margin-left: 12px;
}
&:before {
border-color: transparent $backgroundColor transparent transparent;
margin-left: 0;
}
&:hover:after,
&:hover:before {
left: 100%;
top: 0;
}
&:hover:before {
top: 7px;
}
}
//Left tip
&.left-tip {
&:after,
&:before {
@include transition (bottom, $transitionDuration, $transitionFunction, $transitionProperty, $transitionDuration, $transitionFunction);
top: -9999px;
right: 96%;
margin-right: 12px;
}
&:before {
border-color: transparent transparent transparent $backgroundColor;
margin-right: 0;
}
&:hover:after,
&:hover:before {
right: 100%;
top: 0;
}
&:hover:before {
top: 7px;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment