我试过以下几种方法,但它使边界也变红了。我只想把文字变成红色。这有可能吗?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
.class2,
.class2 tr,
.class2 td {
border: solid 2px;
border-collapse: collapse;
}
.class1{
color: red;
}
</style>
</head>
<body>
<table class="class2">
<tr class="class1">
<td>hello</td>
<td>world</td>
</tr>
<tr>
<td>hello</td>
<td>world</td>
</tr>
</table>
</body>
</html>
发布于 2022-12-04 15:14:57
您可以在类中添加一个规则来覆盖边框颜色:
.class1 td {
color: red;
border-color: #000;
}但是,我通常会在主要的边界声明中添加颜色如下:
.class2,
.class2 tr,
.class2 td {
border: solid 2px #000;
border-collapse: collapse;
}发布于 2022-12-04 15:21:30
您需要为文本指定一个带有颜色类的标记,就像使用span元素这样,它应该只对文本着色,同时将边框保留在原始颜色中。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
.class2,
.class2 tr,
.class2 td {
border: solid 2px;
border-collapse: collapse;
}
.class1{
color: red;
}
</style>
</head>
<body>
<table class="class2">
<tr>
<td><span class="class1">hello</span></td>
<td><span class="class1">world</span></td>
</tr>
<tr>
<td>hello</td>
<td>world</td>
</tr>
</table>
</body>
</html>
发布于 2022-12-04 15:03:29
将td从.class1 td中删除,因为td也会在表上应用样式,如果没有指定其他内容,则颜色标记只在文本上工作。
https://stackoverflow.com/questions/74677799
复制相似问题