简体   繁体   English

HTML 表格中单元格的工具提示(无 Javascript)

[英]Tooltips for cells in HTML table (no Javascript)

Is it possible to have tooltips for table cells with no JavaScript.是否可以为没有 JavaScript 的表格单元格提供工具提示。 Can't use it.不能用。

have you tried?你有没有尝试过?

<td title="This is Title">

its working fine here on Firefox v 18 (Aurora), Internet Explorer 8 & Google Chrome v 23x它在 Firefox v 18 (Aurora)、Internet Explorer 8 和 Google Chrome v 23x 上运行良好

The highest-ranked answer by Mudassar Bashir using the "title" attribute seems the easiest way to do this, but it gives you less control over how the comment/tooltip is displayed. Mudassar Bashir 使用“title”属性给出的排名最高的答案似乎是最简单的方法,但它让您无法控制评论/工具提示的显示方式。

I found that The answer by Christophe for a custom tooltip class seems to give much more control over the behavior of the comment/tooltip.我发现 Christophe 对自定义工具提示类的回答似乎可以更好地控制评论/工具提示的行为。 Since the provided demo does not include a table, as per the question, here is a demo that includes a table .由于提供的演示不包含表格,根据问题,这里是一个包含表格的演示

Note that the "position" style for the parent element of the span (a in this case), must be set to "relative" so that the comment does not push the table contents around when it is displayed.请注意,span 的父元素(在本例中为 a)的“position”样式必须设置为“relative”,以便注释在显示时不会推动表格内容。 It took me a little while to figure that out.我花了一点时间才弄明白。

 #MyTable{ border-style:solid; border-color:black; border-width:2px } #MyTable td{ border-style:solid; border-color:black; border-width:1px; padding:3px; }.CellWithComment{ position:relative; }.CellComment{ display:none; position:absolute; z-index:100; border:1px; background-color:white; border-style:solid; border-width:1px; border-color:red; padding:3px; color:red; top:20px; left:20px; }.CellWithComment:hover span.CellComment{ display:block; }
 <table id="MyTable"> <caption>Cell 1,2 Has a Comment</caption> <thead> <tr> <td>Heading 1</td> <td>Heading 2</td> <td>Heading 3</td> </tr> </thead> <tbody> <tr></tr> <td>Cell 1,1</td> <td class="CellWithComment">Cell 1,2 <span class="CellComment">Here is a comment</span> </td> <td>Cell 1,3</td> <tr> <td>Cell 2,1</td> <td>Cell 2,2</td> <td>Cell 2,3</td> </tr> </tbody> </table>

Yes.是的。 You can use the title attribute on cell elements, with poor usability, or you can use CSS tooltips (several existing questions, possibly duplicates of this one).您可以在单元格元素上使用title属性,可用性较差,或者您可以使用 CSS 工具提示(几个现有问题,可能与此重复)。

You can use css and the:hover pseudo-property.您可以使用 css 和:hover 伪属性。 Here is a simple demo .这是一个简单的演示 It uses the following css:它使用以下 CSS:

a span.tooltip {display:none;}
a:hover span.tooltip {position:absolute;top:30px;left:20px;display:inline;border:2px solid green;}

Note that older browsers have limited support for:hover.请注意,旧版浏览器对:hover 的支持有限。

An evolution of what BioData41 added... BioData41 添加的内容的演变......

Place what follows in CSS style将以下内容置于 CSS 样式中

     <style>

        .CellWithComment{position:relative;}

        .CellComment
        {
            visibility: hidden;
            width: auto;
            position:absolute; 
            z-index:100;
            text-align: Left;
            opacity: 0.4;
            transition: opacity 2s;
            border-radius: 6px;
            background-color: #555;
            padding:3px;
            top:-30px; 
            left:0px;
        }   
        .CellWithComment:hover span.CellComment {visibility: visible;opacity: 1;}
</style>

Then, use it like this:然后,像这样使用它:

        <table>
            <tr>
                <th class="CellWithComment">Category<span class="CellComment">"Ciaooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"</span></th>
                <th class="CellWithComment">Code<span class="CellComment">"Ciaooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"</span></th>
                <th>Opened</th>
                <th>Event</th>
                <th>Severity</th>           
                <th>Id</th>
                <th>Component Name</th>
            </tr>
            <tr>
                <td>Table cell</td>
                <td>Table cell</td>
                <td>Table cell</td>
                <td>Table cell</td>
                <td>Table cell</td>
                <td>Table cell</td>
                <td>Table cell</td>
            </tr>
            <tr>
                <td>Table cell</td>
                <td>Table cell</td>
                <td>Table cell</td>
                <td>Table cell</td>
                <td>Table cell</td>
                <td>Table cell</td>
                <td>Table cell</td>
            </tr>
        </table>
if (data[j] =='B'){
    row.cells[j].title="Basic";
}

In Java script conditionally adding title by comparing value of Data.在 Java 脚本中,通过比较数据的值有条件地添加标题。 The Table is generated by Java script dynamically.该表由 Java 脚本动态生成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM