2011-09-29 37 views
0

我原以爲下面的CSS會起作用;無法修復HTML表格中的單元格寬度

table#ScheduledLeaveCalendar 
{ 
table-layout:fixed; 
} 

/* Calendar that shows annual leave */ 
#ScheduledLeaveCalendar 
{ 
    border-collapse:collapse; 
} 
#ScheduledLeaveCalendar td, #ScheduledLeaveCalendar th 
{ 
    font-size:0.8em; 
    border:1px solid #2906A6; /* dark blue */ 
    padding:3px 3px 2px 3px; 
    width:30px; 
} 
#ScheduledLeaveCalendar th 
{ 
    font-size:0.9em; 
    text-align:center; 
    padding-top:5px; 
    padding-bottom:4px; 
    background-color:#6640EE; /* blue */ 
    color:#ffffff; 
} 

這個html對於MVC開發者來說是有意義的;

<table id="ScheduledLeaveCalendar"> 
    <%: Html.DisplayFor(x => x.cvm.Header1)%> 
    <%: Html.DisplayFor(x => x.cvm.Header2)%> 
    <%: Html.DisplayFor(x => x.cvm.Header3)%> 
    <%: Html.DisplayFor(x => x.cvm.Lines)%> 
</table> 

但是由於某些原因,它沒有。它似乎忽略了固定的屬性 - 我正在使用IE8。 有這個問題的測試包裝或滾動條沒有問題。

這是呈現的HTML,經過編輯以刪除重複的代碼;

<table id="ScheduledLeaveCalendar"> 
<tr> 
     <th colspan="2"></th> 
     <th colspan="6">Apr 2011</th> 
     <th colspan="6">Apr 2011</th> 
     <th colspan="6">Apr 2011</th> 
     <th colspan="6">Apr 2011</th> 
     <th colspan="6">May 2011</th> 
     <th colspan="6">May 2011</th> 
     <th colspan="6">May 2011</th> 
     <th colspan="6">May 2011</th> 
     <th colspan="6">May/Jun 2011</th> 
</tr> 
    <tr id="CalendarHeader2Row"> 
      <th> 
       F 
      </th> 

      <th> 

      </th> 

      <th> 
       M 
      </th> 

      <th> 
       T 
      </th> 

      <th> 
       W 
      </th> 

      <th> 
       T 
      </th> 

      <th> 
       F 
      </th> 

      <th> 

</tr> 
    <tr id="CalendarHeader3Row> 


      <th> 
       1 
      </th> 

      <th> 

      </th> 

      <th> 
       4 
      </th> 

      <th> 
       5 
      </th> 

      <th> 
       6 
      </th> 

      <th> 
       7 
      </th> 

      <th> 
       8 
      </th> 


</tr> 
<tr id="CalendarLines"> 
    <td class="StandardCellHeight DefaultColour"></td> 
    <td class="StandardCellHeight DefaultColour"></td> 
    <td class="StandardCellHeight DefaultColour"></td> 
    <td class="StandardCellHeight DefaultColour"></td> 
    <td class="StandardCellHeight DefaultColour"></td> 
    <td class="StandardCellHeight DefaultColour"></td> 
    <td class="StandardCellHeight DefaultColour"></td> 
    <td class="StandardCellHeight DefaultColour"></td> 
    <td class="StandardCellHeight DefaultColour"></td> 
    <td class="StandardCellHeight DefaultColour"></td> 
    <td class="StandardCellHeight DefaultColour"></td> 
    <td class="StandardCellHeight DefaultColour"></td> 
    <td class="StandardCellHeight DefaultColour"></td> 
    <td class="StandardCellHeight DefaultColour"></td> 
    <td class="StandardCellHeight DefaultColour"></td> 
    <td class="StandardCellHeight DefaultColour"></td> 
    <td class="StandardCellHeight DefaultColour"></td> 
    <td class="StandardCellHeight DefaultColour"></td> 
    <td class="StandardCellHeight BankHolidayColour"></td 
</tr> 
</table> 

這是什麼被渲染,單元格有不同的寬度; enter image description here

+0

如果您可以顯示呈現的HTML(即瀏覽器看到的而不是服務器源),這將會很有幫助。渲染問題始終在客戶端上,所以雖然服務器代碼可能有用,但客戶端HTML非常重要。 – Chris

+0

嘗試在IE中使用F12,然後單擊問題元素以查看它正在繼承的CSS,以嘗試確定問題所在。如果覆蓋「固定」,我的猜測是別的。 –

+0

我點擊了F12,我發現表格佈局是固定的,單元格的寬度是30px,就像我的意圖一樣,儘管它不是以這種方式渲染的。 – arame3333

回答

0

我試圖重新創建您所看到的問題,請參閱下面鏈接的圖像。

http://i.imgur.com/Vdqc0.jpg

該圖像顯示在IE8模式,所使用的HTML和CSS表。細胞似乎是固定的。但我不確定這是什麼,你問

也看看這篇文章http://www.w3schools.com/cssref/pr_tab_table-layout.asp這需要html頁面有一個DOCTYPE固定佈局在IE8中工作。

+0

標題中有文字,TD不會,只是背景顏色。所以如果一個標題單元格的「28」,寬度比它有「1」更大 – arame3333

+0

是的,我看了W3schools網站。 – arame3333

+0

這是否解決? – Coops