如何交替 table 颜色并保持正文背景?
How do i alternate table colors and keep the body background?
(运行 代码 PLS)
我怎样才能将黑色块的颜色更改为白色,与 table
的其余部分颜色相同
<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>
不要注意这个随机文本它会让我 post causywe9yfywe yf w87f78wey f wef7 ywe f8we f87weyf we fwef87wef87yweqfqwief q fqwefweyf wuqydfwefwd w df ywdq f87wd8 fw8df fy wd w 8fwddf wdf wdd wf w 我的代码太多了哈哈 aueuauydyuwgudgasjhvjagefaifagfyus87agfgyufasuigdafyuf87agfg8tf7aiehgfhauy3gfyugsagf
更改这两个规则:
tr:nth-child(even) {
background-color: white;
}
td:nth-child(even) {
background-color: white;
}
至
tr {
background-color: white;
}
td {
background-color: white;
}
(运行 代码 PLS) 我怎样才能将黑色块的颜色更改为白色,与 table
的其余部分颜色相同<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>
不要注意这个随机文本它会让我 post causywe9yfywe yf w87f78wey f wef7 ywe f8we f87weyf we fwef87wef87yweqfqwief q fqwefweyf wuqydfwefwd w df ywdq f87wd8 fw8df fy wd w 8fwddf wdf wdd wf w 我的代码太多了哈哈 aueuauydyuwgudgasjhvjagefaifagfyus87agfgyufasuigdafyuf87agfg8tf7aiehgfhauy3gfyugsagf
更改这两个规则:
tr:nth-child(even) {
background-color: white;
}
td:nth-child(even) {
background-color: white;
}
至
tr {
background-color: white;
}
td {
background-color: white;
}