基于表格边框值的CSS选择器

3

我希望通过CSS选择器访问页面中的一个table

这个表格的结构如下:

<table border="1" width="560" cellspacing="0">
   <tr>
     <td height="28" colspan="3" bgcolor="#FFFFF...>
 </tr>
</table>

基本上我需要一行内的 jQuery 或 CSS 选择器来访问带有 border=1table
没有与 table 相关联的类或 ID,也不可能使用父子映射进行第 n 次访问。
基本上,需要一个选择器来匹配带有 border=1tableborder = 1 不在 style="" 中),它仅是 HTML 标记。
<table border=1"> ....</table>

2
你想要的是 table[border=1] 吗? - Satpal
2
顺便提一下,使用内联属性进行表现(例如widthcellspacingbgcolor)已经被弃用,应该移动到样式表中使用CSS。 - David Thomas
2个回答

8
你可以使用属性选择器

[attr=value]

表示具有属性名称为attr且值恰好为"value"的元素。

table {
  width: 100%;
  height: 50px
}
table[border="1"] {
  background: red
}
<table border="1">
  <tr>
    <td></td>
  </tr>
</table>
<hr />
<table>
  <tr>
    <td></td>
  </tr>
</table>


注意: 我建议不要使用HTML标签border,因为它已经过时了。如果想要给table添加边框,可以使用CSS属性border来进行样式设置。

5

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接