如何在表头中添加bootstrap工具提示?

时间:2018-01-18 15:17:48

标签: html twitter-bootstrap tooltip

我在表头中使用默认引导工具提示。它显示了不相关的行为,比如它增加了标题的宽度。

这是codepen链接

https://codepen.io/tumulalmamun/pen/mpQzBV



$(document).ready(function(){
    $('[data-toggle="tooltip"]').tooltip();   
});

<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h3>Tooltip Example</h3>
  <p>The data-placement attribute specifies the tooltip position.</p>
      <div class="row">
      <div class="col-lg-3">
            <table class="table table-bordered table-hover table-striped">
                <thead>
                    <tr><th colspan="2"> status (Overall)</th></tr>
                    <tr>
                        <th colspan="2" data-toggle="tooltip" data-placement="right" title="Hooray!">
                            Pending 

                        </th>

                    </tr>
                    <tr>
                        <th data-toggle="tooltip" data-placement="right" title="Hooray!">M</th>
                        <th data-toggle="tooltip" data-placement="right" title="Hooray!">O</th>
                    </tr>  
                </thead>
</table>
        
      </div>     
     
 <div class="col-lg-3"></div>
      <div class="col-lg-3"></div>

    </div>
</div>

</body>
</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

修复是将工具提示添加到th / td内部的元素而不是直接在其上。 (我在您的示例中看到的文本周围添加了div)

<table class="table table-bordered table-hover table-striped">
    <thead>
        <tr>
            <th colspan="5">Pre-Recruitment status (Overall)</th>
        </tr>
        <tr>
            <th rowspan="2" colspan="2">Status </th>
            <th rowspan="2">Candidate</th>
            <th colspan="2">
                <div data-toggle="tooltip" data-placement="right" title="Hooray!">Panding Doc.</div>
            </th>
        </tr>
        <tr>
            <th>
               <div data-toggle="tooltip" data-placement="right" title="Hooray!">M</div>
            </th>
            <th>
                <div data-toggle="tooltip" data-placement="right" title="Hooray!">O</div>
            </th>
        </tr>  
    </thead>
</table> 

当显示工具提示时,它会在具有data-toggle="tooltip"属性的元素之后直接向标记添加新div(使用开发工具检查以查看此情况)。因此,它会破坏您的表格布局,因为工具提示将放在之后表格元素。如果在表元素内完成,则布局不会受到影响。

我已将您的codepen与solution分开。