Skip to content

Instantly share code, notes, and snippets.

@maddesigns
Created April 15, 2015 12:10
Show Gist options
  • Save maddesigns/0125432f62d74ec2418f to your computer and use it in GitHub Desktop.
Save maddesigns/0125432f62d74ec2418f to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
<p><span class="c-title-bubble" data-title="Hey, a tooltip!">You should hover me</span></p>
<p><span class="c-title-bubble c-title-bubble--n" data-title="Hey, a tooltip!">You should hover me, too</span></p>
<p><span class="c-title-bubble c-title-bubble--w" data-title="Hey, a tooltip!">And me, whatever</span></p>
<p><span class="c-title-bubble c-title-bubble--e" data-title="Hey, a tooltip!">Lol ok one more</span></p>
// ----
// Sass (v3.4.12)
// Compass (v1.0.3)
// ----
//-----------------------------
//
// Title Bubble
// ============
//
// A tipsy-like tooltip component with default south direction
//
// Usage:
// <div class="c-title-bubble [c-title-bubble--n | --e | --w]" data-title="Some text">
// {{content}}
// </div>
//
//-----------------------------
$c-title-bubbleColor: #3d464d;
$c-title-bubblePointWidth: 5px;
.c-title-bubble {
display: inline-block;
position: relative;
&:before, &:after {
z-index: 1000;
}
&:after {
content: attr(data-title);
position: absolute;
display: none;
top: 100%;
left: 50%;
white-space: nowrap;
padding: 7px 9px;
margin-top: $c-title-bubblePointWidth;
font-size: 11px;
font-weight: 500;
color: #fff;
background-color: $c-title-bubbleColor;
border-radius: 3px;
transform: translateX(-50%);
transform-origin: 50% 50%;
}
&:before {
content: '';
position: absolute;
display: none;
top: 100%;
left: 50%;
margin-left: -$c-title-bubblePointWidth;
margin-top: -($c-title-bubblePointWidth);
border: 5px solid transparent;
border-bottom-color: $c-title-bubbleColor;
}
&--n {
&:after {
top: auto;
bottom: 100%;
margin-bottom: $c-title-bubblePointWidth;
}
&:before {
top: auto;
bottom: 100%;
border-bottom-color: transparent;
border-top-color: $c-title-bubbleColor;
margin-bottom: -$c-title-bubblePointWidth;
}
}
&--e {
&:after {
top: 50%;
left: 100%;
margin-left: $c-title-bubblePointWidth;
margin-top: 0;
transform: translateY(-50%);
}
&:before {
top: 50%;
left: 100%;
border-bottom-color: transparent;
border-right-color: $c-title-bubbleColor;
margin-top: -$c-title-bubblePointWidth;
}
}
&--w {
&:after {
top: 50%;
right: 100%;
left: auto;
margin-right: $c-title-bubblePointWidth;
margin-top: 0;
transform: translateY(-50%);
}
&:before {
top: 50%;
right: 100%;
left: auto;
border-bottom-color: transparent;
border-left-color: $c-title-bubbleColor;
margin-right: -$c-title-bubblePointWidth;
margin-top: -$c-title-bubblePointWidth;
}
}
&:hover, &:focus {
&:before, &:after {
display: block;
// Uncomment this line to disable tooltip interaction:
// pointer-events: none;
}
}
}
.c-title-bubble {
display: inline-block;
position: relative;
}
.c-title-bubble:before, .c-title-bubble:after {
z-index: 1000;
}
.c-title-bubble:after {
content: attr(data-title);
position: absolute;
display: none;
top: 100%;
left: 50%;
white-space: nowrap;
padding: 7px 9px;
margin-top: 5px;
font-size: 11px;
font-weight: 500;
color: #fff;
background-color: #3d464d;
border-radius: 3px;
transform: translateX(-50%);
transform-origin: 50% 50%;
}
.c-title-bubble:before {
content: '';
position: absolute;
display: none;
top: 100%;
left: 50%;
margin-left: -5px;
margin-top: -5px;
border: 5px solid transparent;
border-bottom-color: #3d464d;
}
.c-title-bubble--n:after {
top: auto;
bottom: 100%;
margin-bottom: 5px;
}
.c-title-bubble--n:before {
top: auto;
bottom: 100%;
border-bottom-color: transparent;
border-top-color: #3d464d;
margin-bottom: -5px;
}
.c-title-bubble--e:after {
top: 50%;
left: 100%;
margin-left: 5px;
margin-top: 0;
transform: translateY(-50%);
}
.c-title-bubble--e:before {
top: 50%;
left: 100%;
border-bottom-color: transparent;
border-right-color: #3d464d;
margin-top: -5px;
}
.c-title-bubble--w:after {
top: 50%;
right: 100%;
left: auto;
margin-right: 5px;
margin-top: 0;
transform: translateY(-50%);
}
.c-title-bubble--w:before {
top: 50%;
right: 100%;
left: auto;
border-bottom-color: transparent;
border-left-color: #3d464d;
margin-right: -5px;
margin-top: -5px;
}
.c-title-bubble:hover:before, .c-title-bubble:hover:after, .c-title-bubble:focus:before, .c-title-bubble:focus:after {
display: block;
}
<p><span class="c-title-bubble" data-title="Hey, a tooltip!">You should hover me</span></p>
<p><span class="c-title-bubble c-title-bubble--n" data-title="Hey, a tooltip!">You should hover me, too</span></p>
<p><span class="c-title-bubble c-title-bubble--w" data-title="Hey, a tooltip!">And me, whatever</span></p>
<p><span class="c-title-bubble c-title-bubble--e" data-title="Hey, a tooltip!">Lol ok one more</span></p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment