如果你想在<td>格子内让一个div1绝对定位,如果直接给td一个position:relative
<td colspan="2" style="position:relative;"> <div id="div1" style="position: absolute"> </div> </td>
你会发现是没有用的,div1会蹦出来,然后再给table添加position:relative
发现还是没有用
这里有个解决方案,就是在td,里面再套个div2,把position: relative给div2,如果想让div2跟td大小一样,就再加一个height: 100%,解决:
<td colspan="2"> <div id="div2" style="height: 100%;position: relative"> <div id="div1" position: absolute"> </div> </div> </td>
我以为是跟display有关系,修改td的display的展示方式为block、inline-block都没试出来,为了避免陷入更深的坑,就暂时以上方的这个方案解决了。