2012-04-02 136 views
1

我需要確保表格標題的高度是固定的,並根據標題單元格內容調整寬度。 (標題文本最多顯示兩行)我們如何使用樣式來完成它?另外,我想確保錶行的寬度與標題行的寬度相同(即標題行決定寬度)。固定高度和更改標題寬度(HTML表格)

注意:目前「交易部門所有者別名」排在前面。它需要分兩行。

enter image description here

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head><title> 


</title><link href="Styles/TestStyle.css" rel="stylesheet" type="text/css" /></head> 



<body> 


<div id = "divForTransactionGrid"> 

    <div> 

      <table cellspacing="0" rules="all" border="1" id="grdTransactions" style="border-collapse:collapse;"> 

          <thead> 

              <tr> 

                  <th scope="col">Transaction ID</th><th scope="col">Transaction Name</th><th scope="col">Transaction Owner</th><th scope="col">Transaction Department Owner Alias Name</th> 

              </tr> 

          </thead><tbody> 

              <tr> 

                  <td>1</td><td>TR1</td><td>Lijo</td><td>Lijo</td> 

              </tr><tr> 

                  <td>2</td><td>TR2</td><td>Lijo</td><td>This is a test value to test the result in real time scenario. Row width should be same as header width</td> 

              </tr> 

          </tbody> 

      </table> 

</div> 

</div> 





</body> 

</html> 

CSS

#divForTransactionGrid 

{ 

width: 300px; 

height: 250px; 

overflow:scroll; 

} 
+0

你能花點時間修復一下問題空間嗎? – Aristos 2012-04-02 15:14:36

回答

2

你最大的問題是打破。
Transaction Department Owner Alias Name
讓每一個空間「」突破到一個新行,但是
Transaction&nbsp;Department&nbsp;Owner&nbsp;Alias&nbsp;Name
將迫使句呆在一起,彷彿一個字。

您所要做的就是讓一個固定的空間留在您希望破壞的地方,然後使用您不希望破壞的地方,並且您將有2條或更少的地方。對於正好2行,請使用換行符<br>而不是空格「」。祝你好運。