Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 桌子高度100%在Div元素内_Html_Css - Fatal编程技术网

Html 桌子高度100%在Div元素内

Html 桌子高度100%在Div元素内,html,css,Html,Css,您好,我想将表格高度100%设置为其父div,而不在div中定义高度。我的代码不起作用。我不知道我错过了什么。拨弄 ab C 您需要在div中有一个高度,否则它不知道100%是什么。不给div指定高度值是不可能的 加上这个 body, html{height:100%} div{height:100%} table{background:green; width:450px} ​ 这就是你可以做到的- HTML- 见 更新:如果您不希望对父容器应用100%高度,那么这里有一个jQuer

您好,我想将表格高度100%设置为其父div,而不在div中定义高度。我的代码不起作用。我不知道我错过了什么。拨弄


a
b C
您需要在div中有一个高度
,否则它不知道
100%
是什么。

不给div指定高度值是不可能的

加上这个

body, html{height:100%}
div{height:100%}
table{background:green; width:450px}    ​

这就是你可以做到的-

HTML-

更新:如果您不希望对父容器应用100%高度,那么这里有一个jQuery解决方案可以帮助您-

剧本-

 $(document).ready(function(){
    var b= $(window).height(); //gets the window's height, change the selector if you are looking for height relative to some other element
    $("#tab").css("height",b);
});

他也有类似的问题。我的解决方案是将内桌的固定高度设置为1px,并将内桌中td的高度设置为100%。尽管困难重重,但它工作良好,经过IE、Chrome和FF测试

要将桌子的高度设置为其容器,我必须执行以下操作:

1) 设置“位置:绝对”


2) 删除单元格中的冗余内容(!)

它不工作是什么意思?不在空div上设置高度意味着没有高度,因此设置0的100%为0…div height根据其内容进行扩展,因此无论其高度如何,表上的相同高度我们都不能使用body和html height 100%,因为它将影响我的旧html,而不指定父元素的高度。您不能使用100%的高度。您应该查找jQuery或Javascript解决方案,然后我已经用jQuery解决方案更新了答案。看看这是否对你有帮助。身体高度应为100%,以指定内部任何div的100%高度什么<代码>位置:绝对值与此无关。你能解释一下为什么你认为是这样吗?我不“思考”。我照我写的做了
<div style="overflow:hidden; height:100%">
     <div style="float:left">a<br>b</div>
     <table cellpadding="0" cellspacing="0" style="height:100%;">     
          <tr><td>This is the content of a table that takes 100% height</td></tr>  
      </table>
 </div>
html,body
{
    height:100%;
    background-color:grey;
}
table
{
    background-color:yellow;
}
 $(document).ready(function(){
    var b= $(window).height(); //gets the window's height, change the selector if you are looking for height relative to some other element
    $("#tab").css("height",b);
});