表格列格式
我正在尝试使用 元素格式化
中的列。 我可以设置
background-color
、width
等,但无法设置font-weight
。 为什么不起作用?
<table>
<col style="font-weight:bold; background-color:#CCC;">
<col>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
I'm trying to format a column in a <table/>
using a <col/>
element. I can set background-color
, width
, etc., but can't set the font-weight
. Why doesn't it work?
<table>
<col style="font-weight:bold; background-color:#CCC;">
<col>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
据我所知,您只能在
元素上使用 CSS 来格式化以下内容:
此 页面 有更多信息。
Herb 是对的 - 最好直接设置
的样式。 我所做的如下:
但这在 IE 中不起作用。
As far as I know, you can only format the following using CSS on the
<col>
element:This page has more info.
Herb is right - it's better to style the
<td>
's directly. What I do is the following:This won't work in IE however.
最好的选择是将样式直接应用于
标记。 我从未使用过
标记,但大多数浏览器允许您在
和
那么这个CSS将不起作用
,但这
也将:我假设你上面的代码只是为了演示目的,你实际上不会应用内联样式。
Your best bet is to apply your styling directly to the
<td>
tags. I've never used the<col>
tag, but most browsers let you apply formatting at the<table>
and<td>
/<th>
level, but not at an intermediate level. For example if you havethen this CSS won't work
but this will
Also: I assume your code above is just for demonstration purposes and you're not actually going to apply styles inline.
你可能只需要这个:
You might have just needed this:
您是否尝试过通过 CSS 类应用样式?
以下内容似乎有效:
col 元素的参考
Have you tried applying the style through a CSS class?
The following appears to work:
Reference for the col element
当我尝试设置表格样式时,请阅读本文,使第一列为粗体文本,其他四列为普通文本。
使用 col 标签似乎是可行的方法,但是虽然我可以使用 width 属性设置列的宽度,但 font-weight: 粗体不起作用
感谢您为我指出解决方案的方向。
通过设置所有 td 元素
td {font-weight:bold;}
的样式,然后使用相邻的同级选择器选择第 2-5 列,并将它们设置回正常的td + td {font-体重:正常;}
瞧,一切都好:)
Reading through this as I was attempting to style a table such that the first column would be bold text and the the other four columns would be normal text.
Using col tag seemed like the way to go but while I could set the widths of the columns with the width attribute the font-weight: bold wouldn't work
Thanks for pointing me in the direction of the solution.
By styling all the td elements
td {font-weight: bold;}
and then using an adjacent sibling selector to select columns 2-5 and style them back to normaltd + td {font-weight: normal;}
Voila, alls good :)
col
标签必须位于colgroup
标签内,这可能与问题有关。A
col
tag must be inside of acolgroup
tag, This may be something to do with the problem.