javascript - 我如何交替表格颜色并保持正文背景?
问题描述
(运行代码 PLS)我如何将黑色块颜色更改为白色,与表格的其余部分颜色相同
<body style="background-color:black;">
<div style="color: white;">
<script>
var colors = ["#f2f2f2", "#919191"];
var colorIndex = 0;
function changeColor() {
var col = document.getElementById("body");
if( colorIndex >= colors.length ) {
colorIndex = 0;
}
col.style.backgroundColor = colors[colorIndex];
colorIndex++;
}
</script>
<style>
.bouton{
width: 200px;
border: 3px solid black;
border-radius: 15px;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #ebebeb;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: white;
}
td:nth-child(even) {
background-color: white;
}
</style>
<table>
<tr>
<td>
<xmp>
<!--...-->
</xmp>
</td>
<td>
<xmp>
Defines a comment
</xmp>
</td>
</tr>
<tr>
<td>
<xmp>
<!DOCTYPE>
</xmp>
</td>
<td>
<xmp>
Defines the document type
</xmp>
</td>
</tr>
<tr>
<td>
<xmp>
<a>
</xmp>
</td>
<td>
<xmp>
Defines a hyperlink
</xmp>
</td>
</tr>
<tr>
<td>
<xmp>
<abbr>
</xmp>
</td>
<td>
<xmp>
Defines an abbreviation or an acronym
</xmp>
</td>
</tr>
dont pay atteton to this random text it would let me post causywe9yfywe yf w87f78wey f wef7 ywe f8we f87weyf we fwef87wef87yweqfqwief q fqwefweyf wuqydfwefwd w df ywdq f87wd8 fw8df wd w wd fw fywf w 8fwddf wdf wdd wf wi had too much code lol aueuauydyuwgudgasjhvjagefaifagfyus87agfgyufasuigdafyuf87agfg8tf7aiehgfhauy3gfyugsagf
解决方案
更改以下两条规则:
tr:nth-child(even) {
background-color: white;
}
td:nth-child(even) {
background-color: white;
}
到
tr {
background-color: white;
}
td {
background-color: white;
}
推荐阅读
- html - HTML 打印底部的神秘空白
- python-3.x - '| cut' 未被识别为外部或内部命令
- visual-studio - 将 parquet-tools 添加到路径 (Visual Studio Code)
- javascript - 如何强制文件下载在 iPhone 的新标签页中打开?
- php - 如何将数组值存储在 php 的会话变量中并供以后使用
- java - 如何为基于字符串标准从数组中过滤元素的方法编写测试
- json - 从嵌套的 Json 中提取参数
- mysql - 使用 Workbench 将 MS Access 迁移到 MySQL 时出现日期时间错误
- json - 仅在保存时编译 Angular 项目
- c - 原型与函数定义不匹配,但确实如此