2013-07-10 52 views
7

我有一個表格顯示有關事件的時間跨度的一些信息,並且該特定信息位於嵌套表格中。​​不服從`width`或`max-width`屬性?

以下是截圖:

Nested Table

這裏是包含嵌套表<td>(請忽略RAZOR LOGIC):

<td> 
    <table class="centered" style="width: 100%; table-layout: fixed; white-space: nowrap;"> 
     <tbody> 
      <tr> 
       <td class="left-text" style="max-width: 81px; width: 81px;"><b>All Day?</b></td> 
       <td id="[email protected]" style="width: 160px;">@(item.AllDay.HasValue && item.AllDay.Value == true ? "Yes" : "No")</td> 
      </tr> 
      @*Should display StartTime & EndTime if AllDay == true??*@ 
      <tr id="[email protected]" style="display: @(item.AllDay.HasValue && item.AllDay.Value == true ? "none" : "block")"> 
       <td class="left-text" style="max-width: 81px; width: 81px;"><b>Start Time</b></td> 
       <td id="[email protected]" style="width: 160px;">@item.StartTime</td> 
      </tr> 
      <tr id="[email protected]" style="display: @(item.AllDay.HasValue && item.AllDay.Value == true ? "none" : "block")"> 
       <td class="left-text" style="max-width: 81px; width: 81px;"><b>End Time</b></td> 
       <td id="[email protected]" style="width: 160px;">@item.EndTime</td> 
      </tr> 
     </tbody> 
    </table> 
</td> 

在嵌套表,我有以下款式:

style="width: 100%; table-layout: fixed; white-space: nowrap;" 

對每個左手細胞(即?「全天」,「開始時間」,「結束時間」)我有以下樣式:

style="max-width: 81px; width: 81px;" 

如果不是很明顯,沒有一個嵌套表格的單元格的跟隨我的風格。這有點令人沮喪,因爲我甚至沒有意識到桌子可能會變成如此荒謬的混亂。

我該如何才能強制嵌套表中的所有表格數據單元正確對齊?

回答

22

您需要使用display:table-row;而不是display:block;<tr>標籤。

或者,您可以使用display:none;切換類,而不是切換display值。