单击以显示 CSS 工具提示

use*_*416 4 html css button tooltip

我是使用 CSS 和 HTML 的新手,我一直在尝试使用 CSS 和 HTML 创建工具提示,到目前为止已经成功。但现在想知道是否可能如何使此工具提示仅在单击时出现。再次点击时消失。下面是我使用过的 HTML 代码。如果有人可以建议一些 CSS 来帮助我创建想要的结果,那就太棒了

超文本标记语言

class='tooltips' style ='color:#585858; 文字修饰:none;'>桌面NG信息

提前致谢

小智 6

要切换工具提示,您可以使用复选框的 :checked 伪类。

.tooltip {
  position: relative;
  border-bottom: 1px dotted black;
}
.tooltip span {
  visibility: hidden;
  width: 10em;
  background-color: #000;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  position: absolute;
  z-index: 9;
  top: -1em;
  left:  100%;
  margin-left:1em;
  opacity: 0;
  transition: opacity 1s;
}
.tooltip span::after {
  content: "";
  position: absolute;
  top: 1.5em;
  right: 100%;
  margin-top: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: transparent black transparent transparent;
}
.tooltip input {
  display:none;
}
.tooltip input:checked+span {
  visibility: visible;
  opacity: 1;
}
Run Code Online (Sandbox Code Playgroud)
<p>Hello <label class="tooltip">world<input type="checkbox"><span>and this is the tooltip text displayed on click.</span></label>! I am greeting you.<p>
Run Code Online (Sandbox Code Playgroud)