Advertisement
danine1

tooltip css

Apr 3rd, 2018
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 2.21 KB | None | 0 0
  1. @import "../../lib/styles/colors";
  2.  
  3. // Tooltip container
  4. .tooltip {
  5.   display: inline-flex;
  6.   position: relative;
  7.   z-index: 10;
  8.  
  9.   &.centerX {
  10.     justify-content: center;
  11.   }
  12.   &.centerY {
  13.     align-items: center;
  14.   }
  15.   .tooltipInfo {
  16.     position: absolute;
  17.     visibility: hidden;
  18.     background: $mine-shaft;
  19.     opacity: 0.09;
  20.     color: white;
  21.     text-align: center;
  22.     border-radius: 4px;
  23.     padding: 8px 11px;
  24.     line-height: 1.5;
  25.     font-weight: 400;
  26.     font-size: 1.8rem;
  27.  
  28.     // Fade in tooltip
  29.     opacity: 0;
  30.     transition: opacity 1s;
  31.     width: 180px;
  32.  
  33.     // The arrow which is a cube that we rotate to have traingle
  34.     &:after {
  35.       z-index: 10;
  36.       content: "";
  37.       position: absolute;
  38.       height: 10px;
  39.       width: 10px;
  40.       background: $mine-shaft;
  41.       border-radius: 2px;
  42.     }
  43.     // right tooltip position
  44.     &.right {
  45.       left: calc(100% + 10px);
  46.       opacity: 1;
  47.       bottom: 50%;
  48.       transform: translateY(50%);
  49.       // Triangle positioning
  50.       &:after {
  51.         top: 50%;
  52.         transform: translateY(-50%) rotate(-46deg);
  53.         left: -5px;
  54.         bottom: 0;
  55.       }
  56.     }
  57.     // left tooltip position
  58.     &.left {
  59.       right: calc(100% + 10px);
  60.       opacity: 1;
  61.       top: 50%;
  62.       transform: translateY(-50%);
  63.       // Triangle positioning
  64.       &:after {
  65.         top: 50%;
  66.         transform: translateY(-50%) rotate(135deg);
  67.         right: -4px;
  68.       }
  69.     }
  70.     // Top tooltip position
  71.     &.top {
  72.       // position the cube to the bottom of the container first then move the object itself in x axis by 50%
  73.       bottom: 100%;
  74.       left: 50%;
  75.       transform: translateX(-50%);
  76.       // Triangle positioning
  77.       &:after {
  78.         bottom: -4px;
  79.         transform: translateX(-50%) rotate(225deg);
  80.         left: 50%;
  81.       }
  82.     }
  83.     // Bottom tootlip position
  84.     &.bottom {
  85.       top: 100%;
  86.       left: 50%;
  87.       transform: translateX(-50%);
  88.       &:after {
  89.         top: -4px;
  90.         transform: translateX(-50%) rotate(44deg);
  91.         left: 50%;
  92.       }
  93.     }
  94.   }
  95.   // Show tooltip content on hover
  96.   &:hover {
  97.     .tooltipInfo {
  98.       visibility: visible;
  99.       opacity: 1;
  100.     }
  101.   }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement