HTML如何正确使用工具提示

问题描述 投票:0回答:1

我正试图在我的div中使用工具提示机制。根据文档,这就是我的所作所为:

.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted black;
  /* If you want dots under the hoverable text */
}


/* Tooltip text */

.tooltip .tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: black;
  color: #fff;
  text-align: center;
  padding: 5px 0;
  border-radius: 6px;
  /* Position the tooltip text - see examples below! */
  position: absolute;
  z-index: 1;
}


/* Show the tooltip text when you mouse over the tooltip container */

.tooltip:hover .tooltiptext {
  visibility: visible;
}
<div className="tooltip">
  Info
  <span className="tooltiptext">
        {this.state.singleFunctionality.description}
    </span>
</div>

问题是文本Info根本没有显示。 我使用className因为我正在使用React。

编辑 这是我的渲染函数的完整代码:

render() {
    return (
        <div className="row statusRow">
          {<div><b>{this.state.singleFunctionality.name}</b></div>}
          {<div className="tooltip">Info<span className = "tooltiptext">{this.state.singleFunctionality.description}</span> </div>}
          {<div>{this.state.singleFunctionality.startTime}</div>}
          {<div>{this.state.singleFunctionality.elapsedTime}</div>}
          {<div>{this.getServiceStatusWidget(this.state.singleFunctionality.status)}</div>}
        </div>
    );

  }

并且是该课程的完整CSS:

.statusRow {
    margin-top: 10px;
    padding-top: 10px;
    padding-bottom: 10px;
    margin-bottom: 10px;
    border-radius: 5px;
    /* background: #0c2e44; */
    background: rgb(12,46,68);
    background: radial-gradient(circle, rgba(12,46,68,1) 0%, rgba(17,69,102,1) 100%);
}

.statusCol {
    text-align: left;
    padding-top: 5px;
    color: #f6fdfe;
}

.tooltip {
    position: relative;
    display: inline-block;
    border-bottom: 1px dotted black; /* If you want dots under the hoverable text */
  }

  /* Tooltip text */
  .tooltip .tooltiptext {
    visibility: hidden;
    width: 120px;
    background-color: black;
    color: #fff;
    text-align: center;
    padding: 5px 0;
    border-radius: 6px;

    /* Position the tooltip text - see examples below! */
    position: absolute;
    z-index: 1;
  }

  /* Show the tooltip text when you mouse over the tooltip container */
  .tooltip:hover .tooltiptext {
    visibility: visible;
  }
html css reactjs tooltip
1个回答
0
投票

您发布的代码似乎没有问题。我对其进行了编辑以使其无特定反应,但工具提示的所需结果就在那里。

.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted black;
  /* If you want dots under the hoverable text */
}


/* Tooltip text */

.tooltip .tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: black;
  color: #fff;
  text-align: center;
  padding: 5px 0;
  border-radius: 6px;
  /* Position the tooltip text - see examples below! */
  position: absolute;
  z-index: 1;
}


/* Show the tooltip text when you mouse over the tooltip container */

.tooltip:hover .tooltiptext {
  visibility: visible;
}
<div class="tooltip">Info<span class="tooltiptext">Description</span> </div>
© www.soinside.com 2019 - 2024. All rights reserved.