【问题标题】:Putting HTML Table in a tooltip inside an icon将 HTML 表格放在图标内的工具提示中
【发布时间】:2020-06-26 14:26:27
【问题描述】:

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

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

这是我编写的代码:

<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>             

编辑:这里有一点snippet

【问题讨论】:

  • 你能分享演示吗
  • @vadivela 我有this,我正在尝试导入 fontawesome,因为图标还没有显示。编辑:图标现在显示。

标签: html css twitter-bootstrap html-table tooltip


【解决方案1】:

我可以使用 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>
        `
    );
}

这是outcome

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-30
    • 2016-11-17
    • 2016-01-28
    • 2015-02-19
    相关资源
    最近更新 更多