Abd*_*mun 6 html css tooltip twitter-bootstrap bootstrap-4
我在表头中使用默认引导工具提示。它显示了不相关的行为,比如 - 它增加了标题的宽度。
这是codepen链接
https://codepen.io/tumulalmamun/pen/mpQzBV
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});Run Code Online (Sandbox Code Playgroud)
<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>Run Code Online (Sandbox Code Playgroud)
解决方法是将工具提示添加到 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>
Run Code Online (Sandbox Code Playgroud)
当显示工具提示时,它会在带有data-toggle="tooltip"属性的元素之后直接向标记添加一个新 div (使用开发工具检查以查看发生的情况)。因此,它会破坏您的表格布局,因为工具提示将放置在表格元素之后。如果在表格元素内完成,则布局不会受到影响。
我已经用解决方案分叉了你的代码笔。