问题描述
我想为表格添加边框,
<table style="border: 1pt solid black;display: inline-block;">
<tbody style="">
<tr>
<th" >Title1</th>
<th" >Title2</th>
</tr>
<tr>
<td t-esc=""/>
<td t-esc=""/>
</tr>
</tbody>
</table>
但是当我尝试添加这种样式时:
<style>
td,th{border:solid 1px;text-align:center;}
</style>
请问有什么帮助吗?谢谢。
我尝试了这两种解决方案,但得到了以下结果:
<table class="table">
<tbody style="">
<tr>
<th >Title1</th>
<th >Title2</th>
</tr>
<tr>
<td > Field1 </td>
<td > Field2 </td>
</tr>
</tbody>
</table>
<table style=" border-collapse: collapse;">
<tbody >
<tr>
<th style=" border-collapse: collapse;" >Title1</th>
<th style=" border-collapse: collapse;" >Title2</th>
</tr>
<tr>
<td style=" border-collapse: collapse;" > Field1 </td>
<td style=" border-collapse: collapse;" > Field2 </td>
</tr>
</tbody>
解决方法
您需要使用额外的 css 属性,如下所示:
table,td,th{
border-collapse: collapse;
}
顺便说一下,在 Odoo 中,引导程序已经包含在内,因此您只需执行以下操作:
<table class="table">
<table>
所以你的最终代码是
<!-- using bootstrap -->
<table class="table table-bordered ">
<tbody>
<tr>
<th>Title1</th>
<th>Title2</th>
</tr>
<tr>
<td> Field1 </td>
<td> Field2 </td>
</tr>
</tbody>
</table>
<!-- hard-coded style -->
<table style="border:solid 1px; border-collapse: collapse;">
<tbody>
<tr>
<th style="border:solid 1px; border-collapse: collapse;">Title1</th>
<th style="border:solid 1px; border-collapse: collapse;">Title2</th>
</tr>
<tr>
<td style="border:solid 1px; border-collapse: collapse;"> Field1</td>
<td style="border:solid 1px; border-collapse: collapse;"> Field2</td>
</tr>
</tbody>
</table>