使用 CSS,如何设置单个单元格或单个列的格式?
使用 CSS,如何设置单个单元格或单个列的格式?
Using CSS, how do I set the formatting of just a single cell or a single column?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
使用 CSS,如何设置单个单元格或单个列的格式?
Using CSS, how do I set the formatting of just a single cell or a single column?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(7)
使用
ID
选择器仅定位页面的一个元素,在本例中为表格单元格:然后在 CSS 中:
井号 (
#
) 标记该名称选择器属于id
。您可以进一步在样式表中将其锁定,以仅应用于具有该 ID 的 TD 单元格,如下所示:如果将
rowspan
属性添加到TD
中,您将能够将其变成一个专栏并保留您可能已经设定的样式。如果您用前面的句点 (.) 标记 CSS 选择器名称,如下所示:
它将针对 HTML 中的
class
选择器,并且如果您将 CSS class 属性应用于标签,如下所示:不要使用
CLASS
,除非它会在页面上出现多次。Use the
ID
selector to target just that one element of the page, in this case, a table cell:Then in the CSS:
That hash symbol (
#
) marks that name selector as belonging to anid
. You can further lock it down in the stylesheet to apply only to a TD cell with that ID like so:If you add in the
rowspan
attribute into theTD
, you'll be able to turn that into a column and keep the styling you may have set out.If you mark the CSS selector name with a preceding period (.), like this:
that will target
class
selectors in the HTML and you can style more than one matching element if you apply the CSS class attribute to the tag, like so:Don't use
CLASS
unless it will appear more than once on the page.为单元格指定一个类名称并设置该类的样式。
Give the cell a class name and style the class.
对于表格单元格,您需要为其提供某种标识符,以便您可以引用它。根据您的需要,这将是一个类或一个 id。
然后,您可以在 CSS 中应用不同的格式:
如果您想对列应用不同的样式,可以使用
标签,但浏览器支持有限。您可能最好手动将该类应用于所有元素(或使用 Javascript)
For table cells, you'll need to give it some sort of identifier such that you can refer to it. Depending on your needs, this will be either a class or an id.
In your CSS you can then apply different formatting:
If you want to apply different styles to a column, there is the
<col>
tag, but browser support is limited. You're probably better to apply that class to all elements manually (or by using Javascript)您可以设置适用的
COLGROUP
样式:You can style the
COLGROUP
that applies:查看 HTML
和
标签,允许您将格式应用于一次整列或相邻的列组。
Check out the HTML
<col>
and<colgroup>
tags, which allow you to apply formatting to entire columns or adjacent groups of columns at once.为单元格/列指定一个类或 id,并使用 css 将格式应用于该单元格/列
give the cell/column a class or id and use css to apply the formatting to that
您可以为一列指定两个名称。 ex
也许这可以解决你的问题?
you can assign two names to a column. ex
perhaps that could solve your problem?