如何制作只有边框线和垂直线html的表

时间:2017-08-11 06:32:48

标签: html css

我需要让这张桌子看起来像在图像中表格中的蓝线是我需要如何制作它请帮助我提前谢谢 enter image description here

<style>

td, th {  
    text-align: left;
    padding: 8px;
}
table{
    border: 1px solid #dddddd;
}
</style>
<table>
  <tr>
    <th>Company</th>
    <th>Contact</th>
    <th>Country</th>
  </tr>
  <tr>
    <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Germany</td>
  </tr>
  <tr>
    <td>Centro comercial</td>
    <td>Francisco Chang</td>
    <td>Mexico</td>
  </tr>
  <tr>
    <td>Ernst Handel</td>
    <td>Roland Mendel</td>
    <td>Austria</td>
  </tr>
 
 
</table>

2 个答案:

答案 0 :(得分:2)

在表格中添加border-collapse:collapse,这会将表格的边框折叠为single border,然后您可以将border-right添加到标签的td。

&#13;
&#13;
td, th {  
    text-align: left;
    padding: 8px;
}
th:nth-child(1), td:nth-child(1){
    border-right:1px solid blue; /*Add this*/
}
th:nth-child(2), td:nth-child(2){
    border-right:1px solid blue; /*Add this*/
}
table{
    border: 1px solid #dddddd;
    border-collapse:collapse;/*Add this*/
}
&#13;
<table>
  <tr>
    <th>Company</th>
    <th>Contact</th>
    <th>Country</th>
  </tr>
  <tr>
    <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Germany</td>
  </tr>
  <tr>
    <td>Centro comercial</td>
    <td>Francisco Chang</td>
    <td>Mexico</td>
  </tr>
  <tr>
    <td>Ernst Handel</td>
    <td>Roland Mendel</td>
    <td>Austria</td>
  </tr>
 
 
</table>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

插入此代码:

td:not(:last-child),th:not(:last-child) {
  border-right: 1px solid blue;
}

table {
   border-collapse: collapse;
  //more code
}

td, th {  
    text-align: left;
    padding: 8px;
}

td:not(:last-child),th:not(:last-child) {
  border-right: 1px solid blue;
}

table {
    border: 1px solid #dddddd;
    border-collapse: collapse;
    
}
<table>
  <tr>
    <th>Company</th>
    <th>Contact</th>
    <th>Country</th>
  </tr>
  <tr>
    <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Germany</td>
  </tr>
  <tr>
    <td>Centro comercial</td>
    <td>Francisco Chang</td>
    <td>Mexico</td>
  </tr>
  <tr>
    <td>Ernst Handel</td>
    <td>Roland Mendel</td>
    <td>Austria</td>
  </tr>
 </table>