【发布时间】:2018-05-08 10:47:16
【问题描述】:
我正在尝试创建一个显示数据表的悬停元素。
我无法在主表上方制作悬停元素堆栈。
我已经尝试了几件事,包括固定位置和调整 z-index,但一切似乎都破坏了悬停元素的格式和位置(即它需要相对于悬停的文本定位并且需要调整宽度和高度)。
示例:https://jsfiddle.net/f1hLrwvf/
span.own3 {
background: #FFFFFF;
opacity: 1;
border: 1px solid #DCDCDC;
color: #000000;
font-size: 12px;
height: auto;
width: auto;
min-width: 300px;
letter-spacing: 1px;
line-height: 14px;
position: absolute;
text-align: justify;
top: 20px;
left: 0px;
display: none;
padding: 2px 5px;
font-family: "Helvetica Neue", Arial, sans-serif;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1), 0 3px 10px 0 rgba(0, 0, 0, 0.09);
}
hover.own2 {
position: relative;
}
hover.own2:hover span {
display: block;
}
.table.hoverstatus>tbody>tr:first-child>th {
border: none;
}
<div style="padding:15px;">
<div class="shadow p-3 mb-5 bg-white rounded table-responsive" style="border: 1px solid #F0F0F0;font-family: 'Poppins', sans-serif;font-size:14px;">
<table id="example" class="table table-striped" width="100%">
<thead>
<tr>
<th>Feeling</th>
<th>Day</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Super
</td>
<td>1</td>
</tr>
<tr>
<td>
<hover class="own2">Great<span class="own3"><table class="table hoverstatus" id="innertable"><tr><th>Row1 Col1</th><th>Row1 Col2</th><th>Row1 Col3</th></tr><tr><td>Row2 Col1</td><td>Row2 Col2</td><td>Row2 Col3</td></tr></table></span></hover>
</td>
<td>2</td>
</tr>
</tbody>
</table>
</div>
</div>
非常感谢任何指导。
【问题讨论】:
-
position: absolute;属性使元素“绝对”基于其最近的position: relative;父元素定位。因此,请尝试使元素“绝对”及其父元素“相对”。