我尝试过这样做,但它似乎被忽略了。我发现有几篇文章说,如果你想这样做,那么你必须确保父对象也是 100%。我有以下内容:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server" style="height:100%">
<title>Untitled Page</title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
<style type="text/css">
.MasterStyle
{
width: 98%;
height: 100%;
}
.ContentStyle
{
width: 100%;
}
.TableStyle
{
width: 133px;
height: 100%;
}
</style>
</head>
<body class="MasterStyle">
<form id="frmMaster" runat="server">
<div class="ContentStyle">
<asp:Label runat="server" Text="My Site Name" Font-Bold="true" Font-Names="MS-Sans"
Style="text-align:right" Width="100%" />
<br />
</div>
<hr />
<table style="width:100%; height:100%" border="true">
<tr>
<td class="TableStyle" style="height:100%">
我的 table 周围有一个边框,可以看到它没有填满高度。谁能告诉我为什么我没有获得 100% 的高度?
最佳答案
我相信这也依赖于浏览器,实现略有不同......
但尝试设置<html>
高度也为 100 %,因为它是 <body>
周围的元素。层次结构是 html
> body
> table
,如果最外面的元素没有设置为100%,里面的元素就不能再变大了。
编辑:
仔细查看您的源代码,我相信您的 table 实际上位于 html
> body
> form
> table
,所以也许您还需要将表单高度设置为 100 %。我注意到你的 <head>
设置为 100 %,最好将其删除,因为 <head>
不是表层次结构的一部分。你从来不知道如何设置 <head>
的高度可能会混淆渲染引擎...
关于asp.net - HTML 将表格高度设置为 100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3545344/