这是一个 jsfiddle:https://jsfiddle.net/55cc077/pvu5cmta/
由于 css height: 100% 仅在元素的父元素具有明确定义的高度时才有效,因此此 jQuery 设置单元格高度。有更好的方法吗?
<script type="text/javascript">
$(function(){
$('.myTable2 tr').each(function(){
var H1 = $(this).height(); // Get the row height
$(this).find('td:first').css({'height': H1 + 'px', 'line-height': H1 + 'px'}); //Set td height to row height
});
});
</script>
最佳答案
仅限 CSS:将表格单元格设置为 position: relative;
将div设置为
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100%;
关于jquery - 使用 jQuery 使一个 div 填充整个表格单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41988291/