I have a requirement for an icon with a styled hover-over tooltip within the <thead>
of a table
. Basically, my hover-over tooltip appears as it should when the user hovers over the icon, however, the bottom half of the tooltip text goes under the <tbody>
data.
I'm fairly sure my issue is purely css
based, and doesn't have anything to do with the fact that the table is styled by DataTables
. The z-index
does not appear to be the issue, as I have tried playing with that with no success. I think it's that the tooltip does not want to be able to show outside of it's <thead>
parent since it starts in the <thead>
.
I have created a TryIt Editor showing the problem, here.
And, since I don't know how long those TryIt Editor URLs last (I assume not forever), I am also including some example code, here:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hover Over Issue Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" type="text/javascript"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" type="text/javascript"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
<script>
$(document).ready(function() {
$('#styledtable').DataTable({
"destroy" : true,
"scrollY" : 300,
"scrollCollapse" : true,
"paging" : true,
"autoWidth" : true,
"ordering" : true,
"searching" : false,
"order" : [ [ 0, 'asc' ] ],
"pageLength" : 20,
"lengthChange" : false,
"pagingType" : "full_numbers",
"dom" : '<"top"ip>rt<"bottom"fl><"clear">'
});
});
</script>
<style>
.mySpecialTooltip {
position: relative;
display: inline-block;
float: right;
top: 0px;
right: 0px;
cursor: pointer;
}
.mySpecialTooltip span {
visibility: hidden;
width: 200px;
background-color: black;
color: white;
text-align: left;
padding: 5px 5px;
border-radius: 6px;
white-space: normal;
font-weight: normal;
font-size: 12px;
position: absolute;
z-index: 2;
top: 100%;
left: 50%;
margin-left: -200px;
}
.mySpecialTooltip:hover span {
visibility: visible;
}
</style>
</head>
<body>
<div class="container">
<h2>Hover Over Issue Example</h2>
<p>I need the hover overs on the top right column icons to show up entirely. Hover over the <b>small orange exclamation mark icon</b> which looks like <img src="https://cdn3.iconfinder.com/data/icons/tiny-icons/warning.png"/> above the <b>email</b> header for an example of the problem.</p>
<table class="table" id="styledtable">
<thead>
<tr>
<th style="border: 0px; !important"></th>
<th style="border: 0px; !important"></th>
<th style="border: 0px; !important">
<div class="mySpecialTooltip">
<img src="https://cdn3.iconfinder.com/data/icons/tiny-icons/warning.png" style="cursor: pointer;"/>
<span>
This is some hover over text. It can be long - long enough that it needs to be able to
float over the data in the top rops of the table. So I will just keep typing to ensure
that this box is very long. This is probably long enough.
</span>
</div>
</th>
</tr>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Any help would be greatly appreciated!
答案 0 :(得分:3)
It would appear this does indeed have to do with Datatables
.
The element.style
on class="dataTables_scrollHead"
has overflow: hidden
. If you remove this, you will have expected functionality.