You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
4.2 KiB

4 months ago
  1. [data-tooltip] {
  2. --arrow-size: 5px;
  3. position: relative;
  4. z-index: 10;
  5. }
  6. /* Positioning and visibility settings of the tooltip */
  7. [data-tooltip]:before,
  8. [data-tooltip]:after {
  9. position: absolute;
  10. visibility: hidden;
  11. opacity: 0;
  12. left: 50%;
  13. bottom: calc(100% + var(--arrow-size));
  14. pointer-events: none;
  15. transition: 0.2s;
  16. will-change: transform;
  17. }
  18. /* The actual tooltip with a dynamic width */
  19. [data-tooltip]:before {
  20. content: attr(data-tooltip);
  21. padding: 10px 18px;
  22. min-width: 50px;
  23. max-width: 300px;
  24. width: max-content;
  25. width: -moz-max-content;
  26. border-radius: 6px;
  27. font-size: 14px;
  28. background-color: rgba(59, 72, 80, 0.9);
  29. background-image: linear-gradient(30deg,
  30. rgba(59, 72, 80, 0.44),
  31. rgba(59, 68, 75, 0.44),
  32. rgba(60, 82, 88, 0.44));
  33. box-shadow: 0px 0px 24px rgba(0, 0, 0, 0.2);
  34. color: #fff;
  35. text-align: center;
  36. white-space: pre-wrap;
  37. transform: translate(-50%, calc(0px - var(--arrow-size))) scale(0.5);
  38. }
  39. /* Tooltip arrow */
  40. [data-tooltip]:after {
  41. content: '';
  42. border-style: solid;
  43. border-width: var(--arrow-size) var(--arrow-size) 0px var(--arrow-size);
  44. /* CSS triangle */
  45. border-color: rgba(55, 64, 70, 0.9) transparent transparent transparent;
  46. transition-duration: 0s;
  47. /* If the mouse leaves the element,
  48. the transition effects for the
  49. tooltip arrow are "turned off" */
  50. transform-origin: top;
  51. /* Orientation setting for the
  52. slide-down effect */
  53. transform: translateX(-50%) scaleY(0);
  54. }
  55. /* Tooltip becomes visible at hover */
  56. [data-tooltip]:hover:before,
  57. [data-tooltip]:hover:after {
  58. visibility: visible;
  59. opacity: 1;
  60. }
  61. /* Scales from 0.5 to 1 -> grow effect */
  62. [data-tooltip]:hover:before {
  63. transition-delay: 0.3s;
  64. transform: translate(-50%, calc(0px - var(--arrow-size))) scale(1);
  65. }
  66. /*
  67. Arrow slide down effect only on mouseenter (NOT on mouseleave)
  68. */
  69. [data-tooltip]:hover:after {
  70. transition-delay: 0.5s;
  71. /* Starting after the grow effect */
  72. transition-duration: 0.2s;
  73. transform: translateX(-50%) scaleY(1);
  74. }
  75. /*
  76. That's it for the basic tooltip.
  77. If you want some adjustability
  78. here are some orientation settings you can use:
  79. */
  80. /* LEFT */
  81. /* Tooltip + arrow */
  82. [data-tooltip-location="left"]:before,
  83. [data-tooltip-location="left"]:after {
  84. left: auto;
  85. right: calc(100% + var(--arrow-size));
  86. bottom: 50%;
  87. }
  88. /* Tooltip */
  89. [data-tooltip-location="left"]:before {
  90. transform: translate(calc(0px - var(--arrow-size)), 50%) scale(0.5);
  91. }
  92. [data-tooltip-location="left"]:hover:before {
  93. transform: translate(calc(0px - var(--arrow-size)), 50%) scale(1);
  94. }
  95. /* Arrow */
  96. [data-tooltip-location="left"]:after {
  97. border-width: var(--arrow-size) 0px var(--arrow-size) var(--arrow-size);
  98. border-color: transparent transparent transparent rgba(55, 64, 70, 0.9);
  99. transform-origin: left;
  100. transform: translateY(50%) scaleX(0);
  101. }
  102. [data-tooltip-location="left"]:hover:after {
  103. transform: translateY(50%) scaleX(1);
  104. }
  105. /* RIGHT */
  106. [data-tooltip-location="right"]:before,
  107. [data-tooltip-location="right"]:after {
  108. left: calc(100% + var(--arrow-size));
  109. bottom: 50%;
  110. }
  111. [data-tooltip-location="right"]:before {
  112. transform: translate(var(--arrow-size), 50%) scale(0.5);
  113. }
  114. [data-tooltip-location="right"]:hover:before {
  115. transform: translate(var(--arrow-size), 50%) scale(1);
  116. }
  117. [data-tooltip-location="right"]:after {
  118. border-width: var(--arrow-size) var(--arrow-size) var(--arrow-size) 0px;
  119. border-color: transparent rgba(55, 64, 70, 0.9) transparent transparent;
  120. transform-origin: right;
  121. transform: translateY(50%) scaleX(0);
  122. }
  123. [data-tooltip-location="right"]:hover:after {
  124. transform: translateY(50%) scaleX(1);
  125. }
  126. /* BOTTOM */
  127. [data-tooltip-location="bottom"]:before,
  128. [data-tooltip-location="bottom"]:after {
  129. top: calc(100% + var(--arrow-size));
  130. bottom: auto;
  131. }
  132. [data-tooltip-location="bottom"]:before {
  133. transform: translate(-50%, var(--arrow-size)) scale(0.5);
  134. }
  135. [data-tooltip-location="bottom"]:hover:before {
  136. transform: translate(-50%, var(--arrow-size)) scale(1);
  137. }
  138. [data-tooltip-location="bottom"]:after {
  139. border-width: 0px var(--arrow-size) var(--arrow-size) var(--arrow-size);
  140. border-color: transparent transparent rgba(55, 64, 70, 0.9) transparent;
  141. transform-origin: bottom;
  142. }