gpt4 book ai didi

CSS大方格——如何生成表格

转载 作者:行者123 更新时间:2023-11-28 18:32:26 24 4
gpt4 key购买 nike

我想制作一个大约 50 列和 50 行的网格,每个单元格的高度和宽度均为 10px。

<!DOCTYPE html>
<html>
<head>
<style>
table
{
border-collapse:collapse;
}
table,th, td
{
border: 1px solid black;
}
td{width:10px;}
tr{height:10px;}
</style>
</head>
<body>

<table border="1">
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>

</body>
</html>

我可以通过编写一百次代码来做到这一点..但我认为应该有一些更实用的方法来通过 css 来做到这一点。谁能帮忙...

最佳答案

我不确定你是否可以在 css 中做到这一点,但你肯定可以用 javascript 做到这一点:

<style>
td {
width: 10px;
border: 1px solid black;
}

tr {
height: 10px;
}
</style>

<script>
function makeCells() {
var t = document.createElement("TABLE");

for (var rows = 0; rows < 50; rows++) {
var newRow = document.createElement("TR");
console.log(newRow);
t.appendChild(newRow);
for (var cols = 0; cols < 50; cols++) {
var newCell = document.createElement("TD");
newRow.appendChild(newCell);
}
}

document.body.appendChild(t);
}

makeCells();
</script>

关于CSS大方格——如何生成表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13875897/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com