TL;DR: Struggling to position and display tooltips in a table due to the constraints of overflow: hidden
.
An example has been created to demonstrate the issue with tooltips not displaying correctly within a table. The problem arises because the table necessitates the use of overflow: scroll
for proper horizontal scrolling functionality. Here is an illustration:
.gap {
height: 50px
}
div.table {
max-width: 200px;
overflow: scroll;
border: 2px solid blue;
display: inline-block;
font-family: 'Roboto Mono';
font-weight: 700;
}
.tr {
display:flex;
}
.td, .th {
border: 1px solid black;
min-width: 60px;
height: 50px;
}
.th {
position: relative;
font-size: 13px;
padding: 2px;
background-color: #888888;
text-align: center;
border-right: 1px solid #555555;
display: inline-block;
box-sizing: border-box;
}
.tip-wrapper {
position: absolute;
}
.tip0 {
visibility: hidden;
position: absolute;
top: -60%;
z-index: 1;
max-width: 325px;
min-width: 160px;
color: #333333;
text-align: left;
background: white;
border: 1px solid black;
}
.tip1 {
visibility: hidden;
position: fixed;
z-index: 1;
max-width: 325px;
min-width: 160px;
color: #333333;
text-align: left;
background: white;
border: 1px solid black;
}
.tooltip:hover .tip0, .tooltip:hover .tip1 {
visibility: visible;
}
<div class='gap'>.</div>
<div class='table'>
<div class='table-headers'>
<div class='tr'>
<div class='th tooltip'>
Z
<div class='tip0'>
Heres the ToolTip For Column Z, getting cut off (bad)
</div>
</div>
<div class='th'>Y</div>
<div class='th tooltip'>
X
<div class='tip-wrapper'>
<div class='tip1'>
Heres the Tooltip For Column X, which doesn't stay at the top (bad)
</div>
</div>
</div>
<div class='th'>W</div>
<div class='th'>V</div>
</div>
</div>
<div class='table-body'>
<div class='tr'>
</div>
<div class='tr'>
<div class='td stick'>A</div>
<div class='td'>B</div>
<div class='td'>C</div>
<div class='td'>D</div>
<div class='td'>E</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
</div>
</div>
Within the table above, the tooltips attached to the Z
and X
header cells are experiencing issues. Specifically:
Column Z: The tooltip for this column is being truncated due to the presence of overflow: hidden
. It's imperative that the table remains horizontally scrollable, making it impossible to remove the overflow
CSS property. However, ensuring the tooltip hovers above the table content without obstructing it is equally important.
Column X: An attempt was made using the approach outlined in another post link provided. Method 1 aimed to allow the tooltip to exist outside the bounds of overflow: hidden
. Unfortunately, when vertically scrolling through the table, the tooltip also moves which is undesirable. Ideally, the tooltip should maintain a consistent vertical position just above the table.
The initial concept of "tooltips embedded within table headers" didn't yield the desired results. As a possible solution, the consideration of creating a separate tooltip div
outside the table's HTML utilizing onMouseOver()
and onMouseOut()
event handlers to position the tooltip based on mouse location and populate it with text is being explored. This could potentially be the only viable approach moving forward.