0

我在表格单元中放置了一个面板并将宽度和高度属性设置为100%,以便面板占用表格单元的 100% 空间,但是当我这样做时面板消失了。只有当我将面板宽度和高度属性设置为100px时,才会显示它。那么如何将面板设置为始终占据其所在表格单元的 100% 呢?

在此示例中,面板不显示:

<asp:Table runat="server" ID="mainTable" Width="100%" Height="100%" BorderColor="Red" BorderWidth="20px" BorderStyle="Solid">
    <asp:TableRow runat="server" ID="mainRow" Width="100%" Height="100%" BorderColor="Purple" BorderWidth="20px" BorderStyle="Solid">
        <asp:TableCell runat="server" ID="maincell" Width="30%" Height="100%" BorderColor="AliceBlue" BorderWidth="20px" BorderStyle="Solid">
            <asp:Panel runat="server" ID="mainpanel" Width="100%" Height="100%" BackColor="Gainsboro"></asp:Panel>
        </asp:TableCell>
        <asp:TableCell runat="server" ID="TableCell1" Width="30%" Height="100%" BorderColor="AliceBlue" BorderWidth="20px" BorderStyle="Solid">
            <asp:Panel runat="server" ID="Panel1" Width="100%" Height="100%" BackColor="Gainsboro"></asp:Panel>
        </asp:TableCell>
        <asp:TableCell runat="server" ID="TableCell2" Width="30%" Height="100%" BorderColor="AliceBlue" BorderWidth="20px" BorderStyle="Solid">
            <asp:Panel runat="server" ID="Panel2" Width="100%" Height="100%" BackColor="Gainsboro"></asp:Panel>
        </asp:TableCell>
    </asp:TableRow>
</asp:table>

我在单元格内放置了一个面板,因为我想稍后将控件放入其中。

4

3 回答 3

0

You need to specify a Unit type as it defaults to pixels (apparently). I cant find out how to specify it in markup so cant really help.

This question has the similar issue: aspnet table - specify TableCell width?

They suggest using CSS instead.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.width.aspx#Y0

webControl.width = Unit.Percentage(100) should work, again not sure where you'd put this as I don't do ASP.

于 2011-11-10T13:46:21.463 回答
0

I think this is due to flaw/optimazation in the browser. The web page renders into correct html, but when the browser renders the page it will skip/remove empty divs. So if you insert some kind of content into one of the divs like &nbsp; the browser will render the divs correctly.

于 2011-11-10T13:47:06.460 回答
0

放在style="empty-cells: show"TableCell 上,IE7 和 FF 可以正确呈现它,但在 IE9 中它确实占用了空间但不占用背景色

        <asp:TableCell runat="server" ID="maincell" Width="30%" Height="100%" BorderColor="AliceBlue"
            BorderWidth="20px" BorderStyle="Solid" style="empty-cells: show">
            <asp:Panel runat="server" ID="mainpanel" Width="100%" Height="100%" BackColor="Gainsboro">
            </asp:Panel>
        </asp:TableCell>

在 css 中玩耍并为每个浏览器设置正确的样式。就是这么累。:/

于 2011-11-10T15:31:03.567 回答