_objects.tooltip.scss 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * A minimal CSS-only tooltip copied from:
  3. * https://codepen.io/mildrenben/pen/rVBrpK
  4. *
  5. * To use, write HTML like the following:
  6. *
  7. * <p class="o-tooltip--left" data-tooltip="Hey">Short</p>
  8. */
  9. $cubic: cubic-bezier(0.64, 0.09, 0.08, 1);
  10. .o-tooltip {
  11. position: relative;
  12. &:after {
  13. opacity: 0;
  14. visibility: hidden;
  15. position: absolute;
  16. content: attr(data-tooltip);
  17. padding: 6px;
  18. top: 1.4em;
  19. left: 50%;
  20. transform: translateX(-50%) translateY(-2px);
  21. background: grey;
  22. font-size: 0.7rem;
  23. color: white;
  24. white-space: nowrap;
  25. z-index: 2;
  26. border-radius: 2px;
  27. transition: opacity 0.2s $cubic, transform 0.2s $cubic;
  28. }
  29. &:hover {
  30. &:after {
  31. display: block;
  32. opacity: 1;
  33. visibility: visible;
  34. transform: translateX(-50%) translateY(0);
  35. }
  36. }
  37. }
  38. .o-tooltip--left {
  39. @extend .o-tooltip;
  40. &:after {
  41. top: 0;
  42. left: 0;
  43. transform: translateX(-102%) translateY(0);
  44. }
  45. &:hover {
  46. &:after {
  47. transform: translateX(-100%) translateY(0);
  48. }
  49. }
  50. }