【问题标题】:How to make the final TD element use up exactly all of the remaining width?如何使最终的 TD 元素完全用完剩余的所有宽度?
【发布时间】:2015-12-14 17:47:09
【问题描述】:

我发现了这个问题:How do I get the rightmost column to fill the remaining space?

这似乎基本上正是我想要的。但是,我的布局没有按预期显示。

我的部分页面如下所示:

<table id="Header" width="100%" cellspacing="0" cellpadding="0" border="0" class="clsBorderColor" style="LEFT:10px; POSITION:relative; TOP:10px;">
 <tr>
  <td colspan="4" >
   <table id="SearchParams" cellspacing="0" cellpadding="1" border="0" style="width:100%" class="clsBorderColor">
    <!-- A few rows and an ASP panel containing another row -->
   </table>
  </td>
 </tr>

 <tr>
  <td colspan="4">
   <table id="DisplayOptions" width="100%" border="0" cellpadding="1" cellspacing="0" class="clsBorderColor">
    <tr>
     <td valign="middle" style="width:auto;">
      <asp:label id="lblRecordsCnt" runat="server" Font-Bold="True" Font-Size="X-Small">Records: </asp:label>
     </td>
     <td valign="middle" align="left" style="width:auto;">
      # of records per page <asp:textbox id="txtNoOfRecords" tabIndex="7" CssClass="clsTextBox40" Runat="server"></asp:textbox>
     </td>
     <td valign="middle" style="white-space:nowrap;width:auto;">
      <asp:button id="cmdRefresh" tabIndex="8" runat="server" Text="Refresh" tooltip="Refresh"></asp:button>
     </td>
     <td valign="middle" style="white-space:nowrap;width:225px;" align="right">
      <asp:button id="cmdSearch" cssclass="clsButton60" runat="server" Text="Search" tooltip="Search"></asp:button>
      <input type="button" id="cmdClose" class="clsButton60" onclick="javascript:mfpOpenPopup('Default','foo');return false;" value="Close" title="Close" />
     </td>
     <td style="width:100%;white-space:nowrap;"></td>
    </tr>
   </table>
  </td>
 </tr>
</table>

(我不想这么说,但&lt;table id="Header"&gt; 实际上包含在另一个&lt;table id="Body"&gt; 中,它具有所有相同的属性和值。这就是为什么SearchParamsDisplayOptions 都在&lt;td colspan="4"&gt; 标签内.)

在 Visual Studio 的设计视图中,它显示的非常接近我想要实现的目标:

但是当我在 IE11 中浏览它时,我得到了这个:

空的&lt;td style="width:100%;white-space:nowrap;"&gt;&lt;/td&gt; 元素将行的其余部分抹去。我尝试为所有前面的&lt;td&gt; 标签指定硬编码值,但最终结果是相同的。我还删除了white-space:nowrap,这似乎也没有什么不同。

如何使此表使用父表的整个宽度,更具体地说,如何使最终的 &lt;td&gt; 元素用尽前面元素不需要的任何东西?

【问题讨论】:

  • 您应该向我们展示 html 输出,而不是您的 asp 代码。并最终提供一个 jsfiddle 或 codepen 来显示您的错误;)
  • 愚蠢的问题,但你真的需要最后一个 td 吗?从屏幕截图看来,您可以将其移除,让表格呈现自然宽度(不是 100%)。
  • 如果最后两个按钮出现在屏幕右侧,则您忘记删除width:100%...Here, a fiddle
  • @MrLister 最后两个按钮由于你前面提到的原因最终在右侧,外部表格的宽度已经是 100%
  • 内表不继承外表的宽度。

标签: html css asp.net


【解决方案1】:

white-space:nowrap 从字面上防止可以应用于您不想“弄脏”的列上的换行。删除该行中的所有宽度,并将该嵌套表中的最后一列的宽度设置为 100%,并在其他列上应用 no-wrap...

    <tr>
        <td colspan="4">
            <table id="DisplayOptions" border="0" cellpadding="1" cellspacing="0" class="clsBorderColor">
                <tr>
                    <td valign="middle" style="white-space: nowrap;">
                        <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="X-Small">Records: </asp:Label>
                    </td>
                    <td valign="middle" align="left" style="white-space: nowrap;"># of records per page
                        <asp:TextBox ID="Textbox1" TabIndex="7" CssClass="clsTextBox40" runat="server"></asp:TextBox>
                    </td>
                    <td valign="middle" style="white-space: nowrap;">
                        <asp:Button ID="Button1" TabIndex="8" runat="server" Text="Refresh" ToolTip="Refresh"></asp:Button>
                    </td>
                    <td valign="middle" style="white-space: nowrap;" align="right">
                        <asp:Button ID="Button2" CssClass="clsButton60" runat="server" Text="Search" ToolTip="Search"></asp:Button>
                        <input type="button" id="cmdClose" class="clsButton60" onclick="javascript: mfpOpenPopup('Default', 'foo'); return false;" value="Close" title="Close" />
                    </td>
                    <td style="width: 100%;"></td>
                </tr>
            </table>
        </td>
    </tr>

【讨论】:

  • 在这和 Lister 的 cmets 之间,我能够使它工作。谢谢
猜你喜欢
  • 2012-03-05
  • 1970-01-01
  • 1970-01-01
  • 2016-01-08
  • 2017-02-12
  • 1970-01-01
  • 1970-01-01
  • 2018-10-26
  • 2013-04-20
相关资源
最近更新 更多