這是一種做法。
套裝position: relative
你的父表,然後使用上隱藏div
,你會切換顯示/隱藏 position: absolute
。
.panel
塊元素將佔用表格(行)的寬度,您可以根據需要調整偏移量以將其放置。
訣竅是隻設置左右偏移量。如果您省略了top
偏移量,則它將默認爲元素的位置,如果它沒有絕對定位。如果這是您需要的,這可以讓您獲得隱藏面板的交錯定位。
或者,如果您設置了top
偏移量,則所有面板都將位於相同的位置,並且它們會相互重疊。
您也可以嘗試在tr
元素上設置position: relative
,但這在Chrome中會中斷(但適用於Firefox和IE)。
table {
border: 1px dotted blue;
position: relative;
}
.panel {
position: absolute;
left: 25%; /* adjust as needed */
right: -25%; /* use -value of left to keep full row width */
border: 1px solid red;
background-color: white;
margin-top: -0.5em;
}
<table>
<tr>
<td>First Cell is Long</td>
<td>
<a>Show Div Link</a>
<div class="panel">(1) Hidden div/panel to be toggled. and text
no longer than the parent table.</div>
</td>
</tr>
<tr>
<td>First Cell is Long</td>
<td>
<a>Show Div Link</a>
<div class="panel">(2) Hidden div/panel to be toggled. and text
no longer than the parent table.</div>
</td>
</tr>
<tr>
<td>First Cell is Long</td>
<td>
<a>Show Div Link</a>
<div class="panel">(3) Hidden div/panel to be toggled. and text
no longer than the parent table.</div>
</td>
</tr>
</table>
使用純javascript?使用Jquery?只有在CSS?你到目前爲止嘗試過什麼? –