gpt4 book ai didi

jquery - 使 TD 内的表格大小与包含 TD 的表格大小相同

转载 作者:太空宇宙 更新时间:2023-11-04 11:47:21 25 4
gpt4 key购买 nike

对于我需要做的,我需要在另一个表的 TD 中有一个表,并且需要该表的单元格与包含表的高度和宽度相同。

一些注意事项:

包含的 TD 不能有固定的高度或宽度,它是根据进入原始表的数据的大小动态创建的,所以这排除了我在内部使用高度和宽度的能力:100%表格(只有当父容器具有固定的宽度或高度时才有可能)。

现在表格的高度设置为100px,只是为了在下面的图片中更容易看到我在上面做的注释,它不能有固定的高度,因为单元格1和单元格2的内容需要位于单元格的最顶部,而单元格又需要位于包含 TD 的最顶部和底部。

整个表格的 HTML 和 CSS 很大,所以这里只是从包含的 TD 开始,以保​​持它的整洁:

.bottomAlign {
vertical-align: bottom;
}

.innerTable {
height: 100px;
}

.topAlign {
vertical-align: top;
}
<td>
<table class="innerTable">
<tr class="topAlign">
<td>Cell 1</td>
</tr>
<tr class="bottomAlign">
<td>Cell 2</td>
</tr>
</table>
</td>

这里有一张图片供引用:enter image description here

最佳答案

这是一个模拟动态大小的 td 的 fiddle ,以及调整内表大小的片段

http://jsfiddle.net/v6hg9vdt/

This is the only part of the fiddle that matters, the rest was just to resize the outer td

var inner = $('.innerTable');
var setInnerSize = function(){
inner.width(inner.parent().width());
inner.height(inner.parent().height());
};

关于jquery - 使 TD 内的表格大小与包含 TD 的表格大小相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30880844/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com