2017-09-08 53 views
-3

如何在HTML中的表格中的列上放置边框? 我们是否使用colspan来完成这些功能?在HTML中的表格中的特定列周围的边框

+0

取决于你有过HTML控件,您可能会发现[''(https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ colgroup)元素可用于样式表列。 – showdev

+5

的可能的复制[CSS:表列之间的边界只有](https://stackoverflow.com/questions/3313456/css-borders-between-table-columns-only)以上 – rndus2r

+0

可能重复后我rndus2r – Zoffa

回答

-1

使用;

td { border: 1px solid #000000; } 

colspan是合并单元格。例如;下面线汇合2个细胞

<tr><td colspan="2">Merged Column</td></tr> 

https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_td_colspan

+2

这是怎么回事在所有**单元**上添加边界,这与**列**不同。 – rndus2r

+0

是的,它会的。如果需要特定列,那么我们可以为该列添加“类”并将边框样式单独分配给该列 – msg

0

这里的一个列边界的不定型各行的同一列的例子。
请参阅<colgroup>以获取更多参考。

table { 
 
    border-collapse: collapse; 
 
} 
 
.outlined { 
 
    border: 1px solid blue; 
 
}
<table> 
 
    <colgroup> 
 
    <col> 
 
    <col class="outlined"> 
 
    <col span="3"> 
 
    </colgroup> 
 
    <tr> 
 
    <td>First</td> 
 
    <td>Second</td> 
 
    <td>Third</td> 
 
    <td>Fourth</td> 
 
    <td>Fifth</td> 
 
    </tr> 
 
    <tr> 
 
    <td>First</td> 
 
    <td>Yellow</td> 
 
    <td>Third</td> 
 
    <td>Fourth</td> 
 
    <td>Fifth</td> 
 
    </tr> 
 
    <tr> 
 
    <td>First</td> 
 
    <td>Yellow</td> 
 
    <td>Third</td> 
 
    <td>Fourth</td> 
 
    <td>Fifth</td> 
 
    </tr> 
 
</table>

0

HTML代码

<table> 
    <tr> 
    <th>Expenses</th> 
    <th>Cost</th> 
</tr> 
<tr> 
    <td>iPhone 8</td> 
    <td>$1200</td> 
    </tr> 
    <tr> 
    <td>MacBook Pro</td> 
    <td>$2800</td> 
    </tr> 
    <tr> 
    <td colspan="2">Sum: $4000</td> 
    </tr> 
</table> 

CSS代码

th, td { 
border: 2px solid black; 
} 

您也可以玩弄表{边境}

-1
<html> 
<head> 
<title></title> 
<style> 
table, th, td { 
    border: 1px solid #000; 
} 
</style> 
</head> 
<body> 
    <table style="width:100%"> 
     <tr> 
      <th>Firstname</th> 
      <th>Lastname</th> 
      <th>Age</th> 
     </tr> 
     <tr> 
      <td>Raju</td> 
      <td>Kumar</td> 
      <td>22</td> 
     </tr> 
     <tr> 
      <td>Mohit</td> 
      <td>Sharma</td> 
      <td>20</td> 
     </tr> 
    </table> 
</body> 
</html>