Created
March 2, 2017 17:02
-
-
Save icodesido/34396c573e4362a7c590ed0add7cc4c1 to your computer and use it in GitHub Desktop.
Tool tips in CSS
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
| .tooltip-toggle { | |
| cursor: pointer; | |
| position: relative; | |
| //Tooltip text container - above element | |
| //You can adjust the position to make the container appear below or beside the element | |
| &::before { | |
| background-color: #000; | |
| border-radius: 5px; | |
| color: #fff; | |
| content: attr(aria-label); //This pulls in the text from the element with the tooltip | |
| left: -80px; //This centers the container above the element | |
| padding: 1rem; | |
| position: absolute; | |
| text-transform: none; | |
| top: -80px; //This places the container above the element that needs a tooltip | |
| transition: all 0.5s ease; | |
| width: 160px; | |
| } | |
| //Tooltip arrow | |
| //You can adjust the position of this to align nicely with the element that | |
| //needs a tooltip. You can also use `transform` to rotate it to make the | |
| //tooltip work below or next to the element. | |
| &::after { | |
| border-left: 5px solid transparent; | |
| border-right: 5px solid transparent; | |
| border-top: 5px solid #000; | |
| content: " "; | |
| font-size: 0; | |
| left: 9px; //This centers the arrow above the element with the tooltip | |
| line-height: 0; | |
| margin-left: -5px; | |
| position: absolute; | |
| top: -12px; //This positions the arrow at the bottom of the container | |
| width: 0; | |
| } | |
| //Setting up the transition | |
| &::before, | |
| &::after { | |
| opacity: 0; | |
| pointer-events: none; | |
| } | |
| //Triggering the transition | |
| &:focus::before, | |
| &:focus::after, | |
| &:hover::before, | |
| &:hover::after { | |
| opacity: 1; | |
| transition: all 0.75s ease; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment