gpt4 book ai didi

HTML 工具提示未显示在 Jupyter 笔记本中

转载 作者:行者123 更新时间:2023-11-27 22:51:24 25 4
gpt4 key购买 nike

我正在关注 this example向 HTML 添加工具提示。它在独立的 HTML 文件中运行,但当我尝试将其嵌入 Jupyter 时,我看不到“Hower over me”文本。

这是我的笔记本代码:

from IPython.core.display import HTML

def _set_css_style(css_file_path):
"""
Read the custom CSS file and load it into Jupyter.
Pass the file path to the CSS file.
"""
styles = open(css_file_path, "r").read()
st = '<style>%s</style>' % styles
return HTML(st)

_set_css_style('styles.css')

HTML("""<body style="text-align:center;">

<p>Move the mouse over the text below:</p>

<div class="tooltip">Hover over me
<span class="tooltiptext">Tooltip text</span>
</div>

<p>Blah blah blah</p>

</body>
""")

这是 css 文件:

/* Tooltip container */
.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;
}

Jupyter 显示:

Move the mouse over the text below:

Blah blah blah

最佳答案

class="tooltip" 更改为 class="ttooltip"(以及相应的 CSS 类名称)修复了它。我猜 Jupyter 已经有一个 tooltip 类,它与新创建的类冲突。

关于HTML 工具提示未显示在 Jupyter 笔记本中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59430725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com