首页 > 解决方案 > 将 HTML 表格放在图标内的工具提示中

问题描述

我一直在尝试将表格放在图标内的工具提示中,主要目标是创建一个小图例,使用黄色/橙色图标来解释这些颜色的含义。

到目前为止,我只设法使图标出现,但没有进一步成功。我现在在“颜色”列中制作的表格只显示颜色的名称,但我想显示一个小方块,用代表颜色的颜色绘制,即红色方块代表红色,蓝色蓝色的正方形......等等。

这是我制作的代码:

<style>
    .tooltip {
        position: relative;
        display: inline-block;
        border-bottom: 1px dotted black;
    }

    .tooltip .tooltiptext {
        visibility: hidden;
        width: 180px;
        background-color: #555;
        color: #fff;
        text-align: center;
        border-radius: 6px;
        padding: 5px 0;
        position: absolute;
        z-index: 1;
        bottom: 125%;
        left: 50%;
        margin-left: -60px;
        opacity: 0;
        transition: opacity 0.3s;
    }

    .tooltip .tooltiptext::after {
        content: "";
        position: absolute;
        top: 100%;
        left: 50%;
        margin-left: -5px;
        border-width: 5px;
        border-style: solid;
        border-color: #555 transparent transparent transparent;
    }

    .tooltip:hover .tooltiptext {
        visibility: visible;
        opacity: 1;
    }
</style>
<a>
   <span class="tooltip">
      <i class="fas fa-info-circle"></i>
      <table class="tooltiptext">
         <thead>
            <tr>
               <th>Color</th>
               <th>Significado</th>
            <tr>
         </thead>
         <tbody>
            <tr>
               <th>Gris</th>
               <th>Comprado</th>
            </tr>
            <tr>
               <th>Verde</th>
               <th>Emergencia</th>
            </tr>
            <tr>
               <th>Verde</th>
               <th>Urgencia</th>
            </tr>
            <tr>
               <th>Verde</th>
               <th>Urgencia Menor</th>
            </tr>
            <tr>
               <th>Verde</th>
               <th>Sin Urgencia</th>
            </tr>
         </tbody>
      </table>
   </span>
</a>             

编辑:这是其中的一小部分

标签: htmlcsstwitter-bootstraphtml-tabletooltip

解决方案


我可以使用 bootstrap 和 javascript 来做到这一点,我使用 js 是为了避免 Visual Studio 出现小问题,因为编译器不允许我在 bootstrap 工具提示的 title 属性中放置类属性。

这是代码:

<a id="information" data-toggle="tooltip"  data-html="true">
   <span><i class="fas fa-info-circle" style="color: #ff9900"></i></span>
</a>
function info() {   

    var infoTooltip = document.getElementById("information");

    infoTooltip.setAttribute("title",
        `
        <table>
            <thead>
                <tr>
                    <th>Colores</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <th><span class="badge badge-danger px-2">Emergencia</span></th>
                </tr>
                <tr>
                    <th><span class="badge badge-warning px-2">Urgencia</span></th>
                </tr>
                <tr>
                    <th><span class="badge badge-success px-2">Urgencia Menor</span></th>
                </tr>
                <tr>
                    <th><span class="badge badge-primary px-2">Sin Urgencia</span></th>
                </tr>
                <tr>
                    <th><span class="badge badge-light px-2">Comprado</span></th>
                </tr>
            </tbody>
        </table>
        `
    );
}

这就是结局


推荐阅读