最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Style on colgroup not working - Stack Overflow

programmeradmin1浏览0评论

I have following colgroup not working properly.

<colgroup class="" style="background-color:#FF0000;"></colgroup>

Please see this jsfiddle. My styles on colgroup not working.

I have following colgroup not working properly.

<colgroup class="" style="background-color:#FF0000;"></colgroup>

Please see this jsfiddle. My styles on colgroup not working.

Share Improve this question asked Jan 24, 2012 at 8:04 Imran Qadir Baksh - BalochImran Qadir Baksh - Baloch 34.1k69 gold badges195 silver badges348 bronze badges 1
  • I found that, td has also contain a color. I to override colgroup color. – Imran Qadir Baksh - Baloch Commented Jan 24, 2012 at 8:09
Add a ment  | 

2 Answers 2

Reset to default 6

Most properties that you can set on colgroup won’t have an effect, since by definitions, table cells inherit properties from tr elements (rows), not columns or column groups (to the extent that there is inheritance).

Set, in CSS, the properties directly on the cell elements. For example, to set the background color of the first two columns, assuming that only td markup is used for the cells, use

td:first-child, td:first-child + td {
  background: #f00;
  color: #fff;
}

Here is an example of colgroup:

<html> <body>

<table width="100%" border="1">   <colgroup style="background-color:#22FF22;"></colgroup>   <colgroup style="background-color:#888888;"></colgroup>   <colgroup style="background-color:#FF0000;"></colgroup>

  <tr>
    <th>A</th>
    <th>B</th>
    <th>C</th>
  </tr>  
  <tr>
    <td>D</td>
    <td>E</td>
    <td>F</td>  
 </tr>  
 <tr>
    <td>G</td>
    <td>H</td>
    <td>I</td> 
 </tr>
</table>

</body> </html>

if your code is bit different show us the more code to repy appropriately..

发布评论

评论列表(0)

  1. 暂无评论