tooltip.css 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. [data-tooltip] {
  2. display: inline-block;
  3. position: relative;
  4. cursor: help;
  5. padding: 4px;
  6. }
  7. /* Tooltip styling */
  8. [data-tooltip]:before {
  9. content: attr(data-tooltip);
  10. display: none;
  11. position: absolute;
  12. background: #000;
  13. color: #fff;
  14. padding: 4px 8px;
  15. font-size: 14px;
  16. line-height: 1.4;
  17. min-width: 100px;
  18. text-align: center;
  19. border-radius: 4px;
  20. }
  21. /* Dynamic horizontal centering */
  22. [data-tooltip-position="top"]:before,
  23. [data-tooltip-position="bottom"]:before {
  24. left: 50%;
  25. -ms-transform: translateX(-50%);
  26. -moz-transform: translateX(-50%);
  27. -webkit-transform: translateX(-50%);
  28. transform: translateX(-50%);
  29. }
  30. /* Dynamic vertical centering */
  31. [data-tooltip-position="right"]:before,
  32. [data-tooltip-position="left"]:before {
  33. top: 50%;
  34. -ms-transform: translateY(-50%);
  35. -moz-transform: translateY(-50%);
  36. -webkit-transform: translateY(-50%);
  37. transform: translateY(-50%);
  38. }
  39. [data-tooltip-position="top"]:before {
  40. bottom: 100%;
  41. margin-bottom: 6px;
  42. }
  43. [data-tooltip-position="right"]:before {
  44. left: 100%;
  45. margin-left: 6px;
  46. }
  47. [data-tooltip-position="bottom"]:before {
  48. top: 100%;
  49. margin-top: 6px;
  50. }
  51. [data-tooltip-position="left"]:before {
  52. right: 100%;
  53. margin-right: 6px;
  54. }
  55. /* Tooltip arrow styling/placement */
  56. [data-tooltip]:after {
  57. content: '';
  58. display: none;
  59. position: absolute;
  60. width: 0;
  61. height: 0;
  62. border-color: transparent;
  63. border-style: solid;
  64. }
  65. /* Dynamic horizontal centering for the tooltip */
  66. [data-tooltip-position="top"]:after,
  67. [data-tooltip-position="bottom"]:after {
  68. left: 50%;
  69. margin-left: -6px;
  70. }
  71. /* Dynamic vertical centering for the tooltip */
  72. [data-tooltip-position="right"]:after,
  73. [data-tooltip-position="left"]:after {
  74. top: 50%;
  75. margin-top: -6px;
  76. }
  77. [data-tooltip-position="top"]:after {
  78. bottom: 100%;
  79. border-width: 6px 6px 0;
  80. border-top-color: #000;
  81. }
  82. [data-tooltip-position="right"]:after {
  83. left: 100%;
  84. border-width: 6px 6px 6px 0;
  85. border-right-color: #000;
  86. }
  87. [data-tooltip-position="bottom"]:after {
  88. top: 100%;
  89. border-width: 0 6px 6px;
  90. border-bottom-color: #000;
  91. }
  92. [data-tooltip-position="left"]:after {
  93. right: 100%;
  94. border-width: 6px 0 6px 6px;
  95. border-left-color: #000;
  96. }
  97. /* Show the tooltip when hovering */
  98. [data-tooltip]:hover:before,
  99. [data-tooltip]:hover:after {
  100. display: block;
  101. z-index: 50;
  102. }