Pure CSS: Center Tooltip Above Text On Hover pt. 2

前端 未结 6 1908
春和景丽
春和景丽 2021-01-13 01:05

Expanding on Pure CSS: Center Tooltip Above Text On Hover -- how does one make the tooltip hover centered relative to its container if the tooltip is wider than said

6条回答
  •  无人共我
    2021-01-13 01:37

    JS Bin

    I achieve your question.

    HTML

    This:

    drag drag drag drag drag

    Hover me

    Should appear as:

    CSS

    .drag-hint {
      position:relative;
      margin: 50px;
    }
    .drag-hint > p {
      background: black;
      color: white;
      width: 100%;
     display: none;
    }
    .drag-hint:hover > p {
      display: inline;
      position:absolute;
      top: -40px;
      left: 0;
      right: 0;
      text-align: center;
    }
    

提交回复
热议问题