2017-03-17 4 views
0

カラムインデックスに基づいて、テーブル内のカラムごとにCSSのwidth属性を設定できますか?すなわちインデックスに基づいてテーブル内のカラムにwidth属性を割り当てます。

table column_with_index_[0] { 
    width: 100px; 
} 
table column_with_index_[1] { 
    width: 200px;  
} 
... 

in .css?単純なテーブル構造

<table> 
    <tbody> 
     <tr> 
      <th></th> 
      <th></th> 
     </tr> 
     <tr> 
      <td></td> 
      <td></td> 
     </tr> 
    </tbody> 
</table> 

などで

... ?

答えて

2

私は通常、このような何か...

tr th:nth-child(1), 
tr td:nth-child(1) { 
    width: 100px;} 

tr th:nth-child(2), 
tr td:nth-child(2) { 
    width: 200px;} 

を行うしかし、あなたはこのようなあなたのHTMLで何かが含まれている場合...

<tr> 
    <th data-index="1"></th> 
    <th data-index="2"></th> 
</tr> 

次に、あなたがそうのようにそれをターゲット可能性が...

tr th[data-index="1"] { 
    width: 100px;} 

CSSでは実際にインデックスをカウントできません。指定できるのはインデックスのみです。

関連する問題