我有一个表格,我需要单元格在每个单元格的右上角有一个元素。
我读过其他几个问同样问题的问题,但似乎没有一个能解决问题。
我读过的一种解决方案是将单元格的内部包装在具有相对定位的 div 中,但这不起作用,因为 div 不会填满整个单元格,即使高度和宽度设置为 100%。
我读过的另一个解决方案是手动设置单元格的高度并将 div 的高度手动设置为相同的值。这对我也不起作用,因为表格是动态生成的,我不能保证单元格的大小。
这是一些说明问题的代码:
<table border="1">
<tr>
<td>
<div style="position:relative; height: 100%; background: yellow;">
<p>This is some content</p>
<div style="position:absolute; right:0px; top:0px; background: red;">
absolute
</div>
</div>
</td>
<td>
<div style="position:relative; height: 100%; background: yellow;">
<p>This is some content</p>
<p>This is some content</p>
<p>This is some content</p>
<p>This is some content</p>
<p>This is some content</p>
<p>This is some content</p>
<div style="position:absolute;right:0px; top:0px; background: red;">
absolute
</div>
</div>
</td>
</tr>
这是该示例的样子http://jsfiddle.net/hqtEQ/
有什么办法可以让红色 div 进入每个单元格的右上角?