简体   繁体   English

相对于表格行(tr)的绝对位置表格单元格(td)

[英]Absolute position table cell (td) relative to table row (tr)

Is it possible to absolute position table cell (td) relative to table row (tr) containing that td. 是否可以相对于包含该td的表行(tr)绝对定位表单元格(td)。

For example consider html as below: 例如考虑如下的html:

<table>
 <tr>
   <td>tr1 td 1</td>
   <td>tr1 td 2</td>
   <td class="last">tr1 td 3</td>
 </tr>
 <tr>
   <td>tr2 td 1</td>
  <td>tr2 td 2</td>
  <td class="last">tr2 td 3</td>
</tr>
<tr>
  <td>tr3 td 1</td>
  <td>tr3 td 2</td>
  <td class="last">tr3 td 3</td>
 </tr>
</table>

and css as below: 和CSS如下:

tr{position:relative}

td.last{ position:absolute; left: 10px; top: 40px}

In above example, can I take out last td from tr and absolute position it relative to tr. 在上面的示例中,我可以从tr中取出最后一个td并将其相对于tr绝对位置。

Edit: Its working in Firefox Version 33.0, but not working in Chrome Version 38. In chrome td positioned with respect to table and not with tr. 编辑:它可以在Firefox 33.0版中使用,但不能在Chrome 38版中使用。

Please check the jsfiddle at http://jsfiddle.net/n5s53v32/2/ . 请通过http://jsfiddle.net/n5s53v32/2/查看jsfiddle。

The browsers are very strict when it comes to tables. 对于表,浏览器非常严格。 It does not work well when you get out of the scope of how tables are designed to work. 当您超出表设计工作范围的范围时,它将无法正常工作。

However, you can use a trick with fixed positioning to cheat the browser into not taking in account the missplaced table cell, since it is absolutelly off the normal flow: 但是,您可以使用定位固定的技巧来欺骗浏览器,使其不考虑放错位置的表格单元,因为它绝对偏离了正常流程:

  • Add a transform property to the table row, so it will act as a fixed position container. transform属性添加到表行,因此它将充当固定位置的容器。 Choose one that will not have any visual impact, like transform: scale(1,1); 选择一个不会产生任何视觉影响的对象,例如transform: scale(1,1);

  • Set the table cell as position: fixed , and then you can move it relatively to the transformed row: 将表格单元格设置为position: fixed ,然后可以将其相对移动到转换后的行:

 tr { position:relative; transform:scale(1,1); } td.last{ position:fixed; left: 10px; top: 40px; } 
 <table> <tr> <td>td 1</td> <td>td 2</td> <td class="last">td 3</td> </tr> <tr> <td>td 1</td> <td>td 2</td> <td class="last">td 3</td> </tr> <tr> <td>td 1</td> <td>td 2</td> <td class="last">td 3</td> </tr> </table> 

您不能将单元格从桌子上移开(我知道)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM