[英]How do I align th and td content of a table using Bootstrap 4?
[英]REACTJS: how to make <th> print only once and align properly with <td>
我有 2 个循环来访问数据。 问题是当我将<th>
放在 Inner 循环之外时, <th>
与<td>
不对齐,如果我将我的<th>
放在内部 for 循环中, <th>
将重复多次。
我怎样才能让我的表头<th>
只出现一次并与表数据<td>
正确对齐?
这是代码:(我正在使用 ReactJS)
<body>{item.table_text_data.map((c,j)=> (
<div>
<table>
<tr><th>bottom</th><th>Height</th><th>Left</th><th>Right</th><th>Text</th></tr>
{c.map((i,k) => { return (
<p key={'child' + k}>
<tr><td>{i.bottom}</td>
<td>{i.height}</td>
<td>{i.right}</td>
<td>{i.left}</td>
<td>{i.text}</td></tr>
</p>
)})}
</table>
</div>))}
</body>
我为此得到的输出是: https : //i.stack.imgur.com/gjNAp.png
所以正如你在上面的截图中看到的, <th>
没有与<td>
对齐。
我怎样才能克服这个? 任何帮助深表感谢。 非常感谢。
尝试遵循有关正确表格格式的文档(例如p
不是tr
等的有效子项)。
尝试这个:
<div>
<table>
<thead>
<tr>
<th>bottom</th>
<th>Height</th>
<th>Left</th>
<th>Right</th>
<th>Text</th>
</tr>
</thead>
<tbody>
{item.table_text_data.map((c,j)=> ( {c.map((i,k) => { return (
<tr key={'child' + k}>
<td>{i.bottom}</td>
<td>{i.height}</td>
<td>{i.right}</td>
<td>{i.left}</td>
<td>{i.text}</td>
</tr>
)})}))}
</tbody>
</table>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.