Css 仅将背景色应用于父表th
我有一个表结构,无法访问jsp文件来添加类文件。我必须通过CSS来管理它。在这种情况下,我需要为第一个表所有th应用背景色。不适用于嵌套表th。我们如何使用CSS实现这一点?示例:Css 仅将背景色应用于父表th,css,html-table,Css,Html Table,我有一个表结构,无法访问jsp文件来添加类文件。我必须通过CSS来管理它。在这种情况下,我需要为第一个表所有th应用背景色。不适用于嵌套表th。我们如何使用CSS实现这一点?示例:您可以执行以下操作: table th:first-child { background: red; } table table th:first-child { background: none; } 我只想给外表一个类,并使用这个: table.class-name th:first-child
您可以执行以下操作:
table th:first-child {
background: red;
}
table table th:first-child {
background: none;
}
我只想给外表一个类,并使用这个:
table.class-name th:first-child {
background: red;
}
您可以这样做:
table th:first-child {
background: red;
}
table table th:first-child {
background: none;
}
我只想给外表一个类,并使用这个:
table.class-name th:first-child {
background: red;
}
据我所知,你可以这样写:
tr th{
background:red;
}
tr table th{
background:none;
}
根据我的理解,请勾选此,您可以这样写:
tr th{
background:red;
}
tr table th{
background:none;
}
选中此项区分第一个表的
th
和第二个表的th
评论后编辑:
看这里
我假设div
是第一个表的父容器
您可以将其替换为表的父级
e、 g.如果body
为父项,则css应为
body > table > tbody > tr > th {
background-color:red;
}
区分第一个表的
th
和第二个表的th
评论后编辑:
看这里
我假设div
是第一个表的父容器
您可以将其替换为表的父级
e、 g.如果body
为父项,则css应为
body > table > tbody > tr > th {
background-color:red;
}
我知道的最简单的方法是使用子选择器
#yourtableId > tbody > tr > th { background: red; }
我知道的最简单的方法是使用子选择器
#yourtableId > tbody > tr > th { background: red; }
每个人都尝试了很多事情来实现这个问题的目标 但是根据HTML,我们可以只编写以下css,并避免子项th获得背景色 在这个解决方案中,我们不需要任何id和类,也不需要任何东西来接受
.gap class
。即使这个类不存在,我们也可以应用css
检查
这是带有.gap
类的CSS
table th {background-color:red;}
table td.gap tr th {background:none;}
table th {background-color:red;}
table td tr th {background:none;}
这是没有的CSS。gap
类
table th {background-color:red;}
table td.gap tr th {background:none;}
table th {background-color:red;}
table td tr th {background:none;}
每个人都尝试了很多事情来达到这个问题的目标 但是根据HTML,我们可以只编写以下css,并避免子项th获得背景色 在这个解决方案中,我们不需要任何id和类,也不需要任何东西来接受
.gap class
。即使这个类不存在,我们也可以应用css
检查
这是带有.gap
类的CSS
table th {background-color:red;}
table td.gap tr th {background:none;}
table th {background-color:red;}
table td tr th {background:none;}
这是没有的CSS。gap
类
table th {background-color:red;}
table td.gap tr th {background:none;}
table th {background-color:red;}
table td tr th {background:none;}
我需要不使用任何css类,那么@Sandeep的答案有什么问题?如果你仍然不想用这个,我已经编辑了我的答案。一定要看它。@PavanKumar:Jashwant的CSS不包含类。它依赖于子组合器(
),这是最合适的解决方案,以达到精确的嵌套级别。优秀的解决方案。工作顺利。你能解释一下它是如何使用你的单一css行的吗?@PavanKumar正如Marat解释的那样,我使用了
。它选择直接子对象(而不是子对象)。请参见:。如果它对你有帮助,请标记答案。我需要不使用任何css类,那么@Sandeep的答案有什么问题?如果你仍然不想用这个,我已经编辑了我的答案。一定要看它。@PavanKumar:Jashwant的CSS不包含类。它依赖于子组合器(
),这是最合适的解决方案,以达到精确的嵌套级别。优秀的解决方案。工作顺利。你能解释一下它是如何使用你的单一css行的吗?@PavanKumar正如Marat解释的那样,我使用了
。它选择直接子对象(而不是子对象)。请参见:。若答案对你们有帮助,请在上面标出。你们能用我的例子把它寄回去吗?bcoz我不能用你的代码来获得它。OP说“我必须通过css来管理它”。所以,他可能无法访问html。@sandeep,我不知道可能是什么,也不知道可能不是什么,你可以应用到我的示例中并将其发回吗?bcoz我不能用你的代码来获得它。OP说“我必须通过css来管理它”。所以,他可能无法访问html。@sandeep,我不知道什么是可能的,什么是不可能的,如果不使用背景:无?我将覆盖上面颜色的颜色。如果您想要不同的颜色或图像,您可以在其上应用。是否可以不使用背景:无?我将覆盖上述颜色的颜色。如果您想要不同的颜色或图像,您可以应用于它。