html - 使用 css resize :both; not working with table 调整表格单元格的大小

标签 html css

使用 css {resize:both;} 调整表格单元格的大小不适用于表格

我需要调整表格及其单元格的大小,可以使用 css 调整大小, css {resize:both;} 在 div 中有效,但在表格标签中无效

<table border="1" style="resize:both;">
<tr>
<td>hi table</td>
<td>hi div</td>
</tr>
<tr>
<td>hi table</td>
<td>hi div</td>
</tr>
<tr>
<td>hi table</td>
<td>hi div</td>
</tr>
</table>

谁能帮忙

最佳答案

要覆盖 Chrome 和 Safari,请使用

th, td { resize: both; overflow: auto; }

不要对整个表格设置初始宽度。不过,您可以设置单元格或列的宽度。

要同时覆盖 Firefox,恐怕您需要用一个类将每个单元格的内容包装在一个 div 上,并将相应的类选择器添加到上面的规则中。这会在每个单元格的 Chrome 和 Safari 上引入两个调整大小的句柄......所以也许你应该使用

<td><div class=cell>...</div></td>

对于每个单元格和 CSS 规则

.cell { resize: both; overflow: auto; width: 100%; height: 100%; }

(不使 td 元素可调整大小)。

这样,所有单元格都可以调整大小,因此整个表格可以间接调整大小(只要您不设置它的宽度和高度)。

原则上,resize 适用于除visible 之外的所有具有overflow 属性的元素。实际上,它的工作方式非常有限,并且在不同的浏览器中也有所不同。

关于html - 使用 css resize :both; not working with table 调整表格单元格的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13412203/

相关文章:

php - 在 WooCommerce 单一产品中显示产品属性列表的简码

javascript - 需要 jquery 模式弹出指导。我究竟做错了什么?

css - 使用表格方法垂直对齐?

html - 即使内容中有全 Angular block ,如何使侧边栏出现在移动内容之后?

html - 无法正确对齐图像上方的文本

javascript - 如何使用 FileSystem API 的 window.requestFileSystem?

javascript - 尝试从网站源代码中理解 javascript 中的这个函数

html - 当窗口调整大小时在这两个元素上应用一些对齐 - Bootstrap 3

iphone - 我不知道如何在我的 css 文件中正确使用媒体选择器来决定为 iPhone 或 iPad 加载哪个图像

css - Chrome 扩展弹出窗口大小和更高的屏幕 DPI