css表示特定表的行和列

Ros*_*ose 3 html css jquery

我有很多html表,其中一个被命名为"table1".我想只给这个表格风格.我用了:

#table1 tr,th,td
  {

   border: 5px solid black;
  }
Run Code Online (Sandbox Code Playgroud)

但是当它执行时,其他表的td , tr, th样式被设置为#table1与样式相同.

我怎样才能将Style赋予特定表格td , tr, th

fca*_*ran 10

您还需要为th和指定父级td

#table1 tr, #table1 th, #table1 td {
    /* ... */
}
Run Code Online (Sandbox Code Playgroud)

否则你会应用那种风格

  • #table1 tr(全tr在里面#table1)
  • th(th无论他们身在何处)
  • td(td无论他们身在何处)

作为一个侧面说明,在某些现代浏览器中的:any伪类是可用的(与-moz--webkit-前缀),以便尽快将更加一致,您可以编写实现

#table1 :any(tr, th, td) {
   ...
}
Run Code Online (Sandbox Code Playgroud)

有助于避免重复.