简体   繁体   English

如何使文本区域与表格对齐并检索表格的高度

[英]How to make a textarea line up with a table and retrieve table's height

I have a table which can have rows and columns added to and removed from it. 我有一个表,可以在其中添加和删除行和列。 I'd like to put a textarea to the side of it which will be kept to the same size as the table, so that it looks good. 我想在其侧面放置一个文本区域,该区域将保持与表格相同的大小,以使其看起来不错。

I have to issues. 我有问题。 First is getting it to show up on the right side of the table (provided there is space, if not it should wrap). 首先是使其显示在表格的右侧(如果有空间,如果没有的话,应该包裹起来)。

I have tried setting style to display: inline-table on the table and it does make the textarea (which is a sibling to the table in the DOM) show up to its right, but it does not line up in IE9, Opera, or Firefox. 我试过设置样式以display: inline-table上的display: inline-table表,它确实使textarea(它是DOM中表格的同级)显示在其右侧,但是在IE9,Opera或火狐浏览器。 The textarea sticks up over the table. 文本区域粘在桌子上。 Works with Webkit. 与Webkit一起使用。 Webkit also has a nice grabber thingy on the bottom right to let me adjust the size. Webkit的右下角还有一个不错的抓取器,让我调整大小。

If I use display: inline-block it now works in Firefox. 如果我使用display: inline-block ,现在可以在Firefox中使用。 Still broken in IE9 and Opera. 仍在IE9和Opera中损坏。

For dynamic resizing, I could just call a function to resize it every time the table changes. 对于动态调整大小,我可以只在表每次更改时调用一个函数来调整大小。

How do I retrieve the size of a table or other element (in pixel units or other units)? 如何检索表格或其他元素的大小(以像素为单位或其他单位)?

Fiddle demonstrating issue: http://jsfiddle.net/7jKDm/4/ 小提琴展示的问题: http : //jsfiddle.net/7jKDm/4/

var height = document.getElementById('tbl').clientHeight;

seems to do the trick. 似乎可以解决问题。 I believe it is in pixels. 我相信以像素为单位。

As far as getting it to align with the table, you can have to last column of your table hold this textarea and rowspan the whole table, or you can set up column divs, which there are plenty of tutorials for with google search. 至于使其与表格对齐,您可能必须在表格的最后一列保留此textarea并在整个表格中rowspan ,或者可以设置列div,其中有很多与google搜索相关的教程。

Seems like this person also got it to work using .offsetHeight 似乎此人也可以使用.offsetHeight使其正常工作

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

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