推荐一篇利用th,colgroup,col定义表格样式

所属分类: 网络编程 / CSS/HTML 阅读数: 921
收藏 0 赞 0 分享
定义表格各列的样式,不用每个td都在那里加一堆的Class,利用th,colgroup,col等属性,轻松搞定^_^
代码如下:
复制代码 代码如下:

<style>
table.Demo {
  border-collapse: collapse;
  color: #454545;
  font: 11px/150% Verdana, Arial, Helvetica, sans-serif;
}
table.Demo th {
  padding: 3px 7px;
  border: 1px solid #f60;
  border-width: 2px 1px 1px;
  background: #ffffe1;
}
table.Demo td {
  padding: 3px 7px;
  border: 1px solid #f60;
}
table.Demo col.Col1 {
  text-align: right;
  background: #f5f5f5;
}
table.Demo col.Col2 {
  color: #00c;
}
table.Demo col.Col3 {
  font-style: italic;
}
</style>
<table class="Demo">
  <tr>
    <th>TagName</th>
    <th>ClassName</th>
    <th>CSS</th>
  </tr>
  <colgroup>
    <col class="Col1" />
    <col class="Col2" />
    <col class="Col3" />
  </colgroup>
  <tr>
    <td>table</td>
    <td>Demo</td>
    <td>border-collapse: collapse;<br />color: #454545;<br />font: 11px/150% Verdana, Arial, Helvetica, sans-serif;</td>
  </tr>
  <tr>
    <td>th</td>
    <td></td>
    <td>padding: 3px 7px;<br />border: 1px solid #f60;<br />border-width: 2px 1px 1px;<br />background: #ffffe1;</td> 
  </tr>
  <tr>
    <td>td</td>
    <td></td>
    <td>padding: 3px 7px;<br />border: 1px solid #f60;</td>
  </tr>
  <tr>
    <td>col</td>
    <td>Col1</td>
    <td>text-align: right;<br />background: #f5f5f5;</td>
  </tr>
  <tr>
    <td>col</td>
    <td>Col2</td>
    <td>color: #00c;</td>
  </tr>
  <tr>
    <td>col</td>
    <td>Col3</td>
    <td>font-style: italic;</td>
  </tr>
</table>

抛砖引玉,更多效果就由你DIY了!

[Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]

更多精彩内容其他人还在看

CHM集锦(CHM)

CHM集锦(CHM)
收藏 0 赞 0 分享

IE与FireFox的兼容性问题

IE与FireFox的兼容性问题
收藏 0 赞 0 分享

DIV 居中的绝好解决方法

DIV 居中的绝好解决方法
收藏 0 赞 0 分享

解决 select 挡住div的解决方法

解决 select 挡住div的解决方法
收藏 0 赞 0 分享

网站首页head区代码规范

网站首页head区代码规范
收藏 0 赞 0 分享

动态更改网页HTML元素(对象)内容

动态更改网页HTML元素(对象)内容
收藏 0 赞 0 分享

如何处理多国语言

如何处理多国语言
收藏 0 赞 0 分享

Firefox CSS私有属性备忘记录

Firefox CSS私有属性备忘记录
收藏 0 赞 0 分享

CSS兼容要点分析

CSS兼容要点分析
收藏 0 赞 0 分享

css静态滤镜 + A:Hover

css静态滤镜 + A:Hover
收藏 0 赞 0 分享
查看更多