2012-07-23 64 views
0

的宽度,我有以下代码:设置HTML表格TD

<table> 
<thead> 
    <th class='1'>Date</th> 
    <th class='2'>Start Time</th> 
    <th class='3'>End Time </th> 
    <th class='4'>Location</th> 
</thead> 
    <tbody> 
    <td class='1'>Date</td> 
    <td class='2'>Start Time</td> 
    <td class='3'>End Time </td> 
    <td class='4'>Location</td> 
</tbody> 
</table>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ 

和CSS

table {width:550px;} 
​.1 {width:60px; background-color:green;} 
.2 {width:90px; background-color:blue;} 
.3 {width:90px; background-color:red;} 
.4 {width:100px; background-color:yellow;}​ 

为什么我不能设置宽度?背景颜色不变,所以我必须有代码错误。

+2

尝试以字母而不是数字开头的类名称。 – 2012-07-23 18:27:01

+0

你不能有一个以数字开头的类名,请参阅http://stackoverflow.com/questions/448981/what-c​​haracters-are-valid-in-css-class-names – 2012-07-23 18:27:56

+0

哦,这工作。谢谢。 – user1015214 2012-07-23 18:29:36

回答

2

类名不能以数字开头。尝试重命名您的课程以开始一封信(a-z)。

JS小提琴:http://jsfiddle.net/sDKp2/

+0

更确切地说,CSS中的类选择器不能包含以数字开头的类名称。按照HTML规范,这样的类名是允许的(并且可以在脚本中使用)。他们甚至可以和CSS一起使用,但是你需要像'[class ='1']'这样的属性选择器而不是像'.1'这样的类选择器(并且属性选择器的支持程度还不如类选择器)。 – 2012-07-23 18:39:10