Html 给一个表格 CSS 类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14610593/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Giving a table CSS class
提问by Jeff Stone
I'm trying to make a table with custom CSS, and I have no idea what I'm doing wrong. Done this before, but for some reason am unable to get the darn CSS to show up... Just shows a blank table with no style.
我正在尝试使用自定义 CSS 制作表格,但我不知道我做错了什么。以前这样做过,但由于某种原因我无法让该死的 CSS 显示出来......只显示一个没有样式的空白表格。
CSS:
CSS:
table.300yardsTable{background:#EEE;color:#333;font-size:14px;text-align:center;}
table.300yardsTableHeader tr{background:#CCC;font-weight:bold;}
table.300yardsRow tr{background:#EEE;color:#333;}
table.300yardsRow:hover tr{background:#242424;color:#CCC;}
Table:
桌子:
<table width="600" border="1" align="center" cellpadding="2" cellspacing="2" class="300yardsTable">
<tr class="300yardsTableHeader">
<td width="25%">LOFT</td>
<td width="25%">HAND</td>
<td width="25%">LIE</td>
<td width="25%">VOLUME</td>
</tr>
<tr class="300yardsRow">
<td>8*-12*</td>
<td>RH/LH</td>
<td>61*</td>
<td>460cc</td>
</tr>
</table>
回答by Paul Radich
Your css is wrong the classes are on the tr's not the table.
你的 css 是错误的,这些类在 tr 上而不是桌子上。
tr.yardsTableHeader tr{background:#CCC;font-weight:bold;}
tr.yardsRow {background:#EEE;color:#333;}
tr.yardsRow:hover{background:#242424;color:#CCC;}
Remove #'s from class names
从类名中删除#
回答by corymathews
You cannot start a css classname with a number. So 300yearsTableHeader is an invalid name
您不能以数字开头 css 类名。所以 300yearsTableHeader 是一个无效的名字
回答by Tom Oakley
I believe you cannot use a number to start a CSS property. Try using .yardsTableinstead of .300yardsTable.
我相信您不能使用数字来启动 CSS 属性。尝试使用.yardsTable代替.300yardsTable.
回答by xan
You are not allowed to start classname with an integer. Check out the fiddle here.
你是不是可以开始class与名称integer。在这里查看小提琴。
回答by N1tr0
As mentioned by others, you can't start the class name with a #. Also, need to either drop the 'table' prefix or change those that are on the tr's with tr.classname
正如其他人所提到的,您不能以 # 开头的类名。此外,需要删除“table”前缀或使用 tr.classname 更改 tr 上的前缀
回答by Michael Malinovskij
.300yardsTable {background:#EEE;color:#333;font-size:14px;text-align:center;}
.300yardsTable .300yardsTableHeader {background:#CCC;font-weight:bold;}
.300yardsTable .300yardsRow {background:#EEE;color:#333;}
.300yardsTable .300yardsRow:hover {background:#242424;color:#CCC;}
Css selector name cannot start with a digit.
CSS 选择器名称不能以数字开头。

