我正在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
答案 0 :(得分:0)
将class="tooltip"
更改为class="ttooltip"
(以及相应的CSS类名称)已修复它。我猜Jupyter已经有一些tooltip
类与一个新创建的类相冲突了。