Html 如何使用 CSS 中的 myclass 类格式化表中包含的所有 td 元素?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2408128/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:26:22  来源:igfitidea点击:

How can I format all td elements contained in a table with class myclass in CSS?

htmlcssstylesheet

提问by codymanix

How can I format all td elements contained in a table with class myclass in CSS?

如何使用 CSS 中的 myclass 类格式化表中包含的所有 td 元素?

I want a format rule which applies to <table class="myclass"><td>FORMAT THIS</td></table>.

我想要一个适用于的格式规则 <table class="myclass"><td>FORMAT THIS</td></table>.

回答by Quentin

With a descendant selector:

使用后代选择器

table.myclass td { — }

回答by Fitzchak Yitzchaki

Don't this simple css will do it?

难道这个简单的css不会做吗?

.myclass td{}

回答by Pekka

 table.myclass td { color: blue }

Your table is missing a trelement by the way.

tr顺便说一下,您的表格缺少一个元素。

回答by Mauro

as far as i am aware you would do this

据我所知你会这样做

table.myclass td { styles in here }

回答by Philip

table.myclass td { ... }

回答by Sarfraz

...........

…………

table.myclass td{
 /* your styles */
}

Have a look at CSS selectors for more info.

查看 CSS 选择器了解更多信息。

回答by LokizFenrir

table#myid td { color: blue }//each td in an individual table with id myid

table#myid td { color: blue }//每个td在一个id为myid的单独表中

table could be dropped but i kept it for semantics.

表可以删除,但我保留它的语义。

#myid.myclass td { color: blue }*//each td in anything with an id of myid and class of myclass. "is an" id(myid) that "has a" class(myclass);-) *

#myid.myclass td { color: blue }*// id 为 myid 和 class 为 myclass 的任何事物中的每个 td。“是一个”id(myid),它“有一个”类(myclass);-) *



things become fun especially when one starts playing with nth-child(x) etc inside "tables"!

事情变得有趣,尤其是当人们开始在“桌子”内玩 nth-child(x) 等时!

the issue seems to be more a case of "Scope"than actualy assigning any css. By assigning an idyou limit.ie control the scopeto an unique element, use classwhen you intend to extend scopeto all elements sharing a class. So theoretically you only need to specify the .myclass td{ etc } , however i just wanted to affirm your intentions and reasoning, happy coding.

这个问题似乎更像是“范围”的情况,而不是实际分配任何 css。通过分配一个ID,你限制.IE控制范围,以一个独特的元素,使用,当你打算扩大范围到共享类的所有元素。所以理论上你只需要指定 .myclass td{ etc } ,但是我只是想确认你的意图和推理,快乐编码。

But yes i agree, please have a look at css selectors, and jquery( Sizzle). It's easy and so ..... powerful. :X

但是是的,我同意,请查看 css 选择器和 jquery( Sizzle)。这很容易,所以..... 强大。:X

CSS Selectors - INCLUDING THE CSS VERSION EACH NEEDS!

CSS 选择器 - 包括每个需要的 CSS 版本!