怎么用css实现多行表头白底色但是内容隔行变色的效果

axer 2006-05-15 05:03:46
代码如下,内容实现了隔行变色,但是表头我不想要变色,仍然要保持白底,怎么弄啊?谢谢大家。
<style type="text/css">
<!--
table{border:1px solid #000;border-width:1px 0 0 1px;margin:2px 0 2px 0;text-align:center;border-collapse:collapse;font-family:"arial"; font-size: 12px; font-style: normal; line-height: 17px;}
td{border:1px solid #000;border-width:0 1px 1px 0;margin:2px 0 2px 0;text-align:left;}
tr{background-color:expression("#FFFFFF,#C0C0C0".split(",")[rowIndex%2])}
r1{background-color :white;}

-->
</style>

<table width="720" align="center" id="table1">

<tr style="BACKGROUND-COLOR: #ffffff">
<td >
<strong>item</strong></td>

<td colSpan="4" rowSpan="2" style="font-family: Arial; font-size: 12px; line-height: 15px">
<strong>Boundary dimensions (mm) </strong></td>
<td colSpan="2" style="font-family: Arial; font-size: 12px; line-height: 15px">
<strong>Basic load ratings </strong></td>
<td colSpan="2" style="font-family: Arial; font-size: 12px; line-height: 15px">
<strong>Limiting speeds </strong></td>
<td>
<strong>Mass </strong></td>
</tr>
<tr>
<td class="r1">
<strong>No. </strong></td>
<td colSpan="2" style="font-family: Arial; font-size: 12px; line-height: 15px">
<strong>N </strong></td>
<td colSpan="2" style="font-family: Arial; font-size: 12px; line-height: 15px">
<strong>RPM </strong></td>
<td>
<strong>Kg </strong></td>
</tr>
<tr style="BACKGROUND-COLOR: #ffffff">
<td>
<strong>open </strong></td>
<td rowSpan="2" style="font-family: Arial; font-size: 12px; line-height: 15px">
<strong>d </strong></td>
<td rowSpan="2" style="font-family: Arial; font-size: 12px; line-height: 15px">
<strong>D </strong></td>
<td rowSpan="2" style="font-family: Arial; font-size: 12px; line-height: 15px">
<strong>B </strong></td>
<td rowSpan="2" style="font-family: Arial; font-size: 12px; line-height: 15px">
<strong>rs min </strong></td>
<td>
<strong>dynamic </strong></td>
<td>
<strong>static </strong></td>
<td>
<strong>Grease </strong></td>
<td>
<strong>oil </strong></td>
<td>
<strong>open </strong></td>
</tr>
<tr>
<td>
<strong>type </strong></td>
<td>
<strong>Cr </strong></td>
<td>
<strong>Cr </strong></td>
<td>
<strong>ZZ , 2RS </strong></td>
<td>
<strong>open </strong></td>
<td>
<strong>type </strong></td>
</tr>
<tr style="BACKGROUND-COLOR: #ffffff">
<td>6000
</td>
<td>10
</td>
<td>26
</td>
<td>8
</td>
<td>0.3
</td>
<td>4550
</td>
<td>1960
</td>
<td>29000
</td>
<td>34000
</td>
<td>0.019
</td>
</tr>
<tr>
<td>6001
</td>
<td>12
</td>
<td>28
</td>
<td>8
</td>
<td>0.3
</td>
<td>5100
</td>
<td>2390
</td>
<td>26000
</td>
<td>30000
</td>
<td>0.021
</td>
</tr>
<tr style="BACKGROUND-COLOR: #ffffff">
<td>6002
</td>
<td>15
</td>
<td>32
</td>
<td>9
</td>
<td>0.3
</td>
<td>5600
</td>
<td>2840
</td>
<td>22000
</td>
<td>26000
</td>
<td>0.030
</td>
</tr>
<tr>
<td>6003
</td>
<td>17
</td>
<td>35
</td>
<td>10
</td>
<td>0.3
</td>
<td>6800
</td>
<td>3350
</td>
<td>20000
</td>
<td>24000
</td>
<td>0.039
</td>
</tr>
</table>

...全文
234 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
axer 2006-05-16
  • 打赏
  • 举报
回复
两位应得的
axer 2006-05-16
  • 打赏
  • 举报
回复
th可行,搞定了,谢谢。
ddcatlee 2006-05-16
  • 打赏
  • 举报
回复
<table>
<tr>
<th>这里是表头</th>
</tr>
<tr>
<td>这里是内容</td>
</tr>
</table>

在css中分别定义 th和td
strongstone 2006-05-16
  • 打赏
  • 举报
回复
所有的表头都使用TH,然后将TH通过CSS定义就行了。
axer 2006-05-15
  • 打赏
  • 举报
回复
to :2楼
我试了一下午,没成功,你看我代码论里面有<table...id="table1">,就是调试时搞的,因为对css不熟,所以能不能麻烦你根据我的实例调整一下代码?谢谢了
to:3楼
不好意思,你没看清我的问题,我的表头是“多行表头”,具体到这段代码,表格一共8行,最后4行是内容,上面4行都是表头(包含几组横向合并和纵向合并的单元格),虽然第一行是白色,但是我要的是1-4行都是白色,也就是说这个8行的表格里仅有第6第8行变色。谢谢
cqq 2006-05-15
  • 打赏
  • 举报
回复
你现在第一行已经是白底了阿
loveyt 2006-05-15
  • 打赏
  • 举报
回复
再写一个你想要的class,把这个样式应用在表头上。

61,115

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧