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



我想通过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 次访问的父子映射也是不可能的

基本上是table border=1(border = 1不在style=""内)的table的选择器,它只是HTML标记

<table border=1"> ....</table>

您可以使用属性选择器

[属性=值]

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

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>


注意:但是,我建议不要使用borderHTML标签,因为它已被弃用。要使用border设置table样式,可以在 CSS 中使用属性border

你的意思是这样吗?

table[border="1"]{
background: red;
}

如果您只想检查是否有边框属性:

table[border]{
background: blue;
}

您可以在此处找到有关此内容的更多信息: https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors

最新更新