2017-09-19 77 views
1

我想擺脫中間的水平線。基本上,我希望桌子有中間的外邊框和垂直分隔線。我如何實現這一目標?擺脫使用CSS的表格中的水平邊框

JS小提琴 - https://jsfiddle.net/kac69ovn/

table { 
 
    width: 85%; 
 
    border-collapse: collapse; 
 
    margin-left: 4%; 
 
    border: 1px solid black; 
 
} 
 

 
th { 
 
    text-align: left; 
 
    width: 50%; 
 
    border: 1px solid black; 
 
    padding: 5px 11px; 
 
} 
 

 
td { 
 
    text-align: left; 
 
    width: 50%; 
 
    border: 1px solid black; 
 
    padding: 5px 11px; 
 
}
<table> 
 
    <tbody> 
 
    <tr> 
 
     <th>Firstname</th> 
 
     <th>Lastname</th> 
 
    </tr> 
 
    <tr> 
 
     <td>Lorem Ipsum is simply dummy text of the printing and </td> 
 
     <td>It is a long established fact that a </td> 
 
    </tr> 
 
    </tbody> 
 
</table>

提前感謝!

回答

0

您可以用邊界撥弄:

  1. 設置border-top: nonetd小號

  2. 設置border-bottom: noneth

  3. 添加是爲了防止水平線,當有多個tr S:

    tr:not(:last-child) td { 
    border-bottom: none; 
    } 
    

請參見下面的演示:

table { 
 
    width: 85%; 
 
    border-collapse: collapse; 
 
    margin-left: 4%; 
 
    /*border: 1px solid black;*/ 
 
} 
 

 
th { 
 
    text-align: left; 
 
    width: 50%; 
 
    border: 1px solid black; 
 
    border-bottom: none; /* ADDED */ 
 
    padding: 5px 11px; 
 
} 
 

 
td { 
 
    text-align: left; 
 
    width: 50%; 
 
    border: 1px solid black; 
 
    border-top: none; /* ADDED */ 
 
    padding: 5px 11px; 
 
} 
 

 
tr:not(:last-child) td { /* ADDED */ 
 
    border-bottom: none; 
 
}
<table> 
 
    <tbody> 
 
    <tr> 
 
     <th>Firstname</th> 
 
     <th>Lastname</th> 
 
    </tr> 
 
    <tr> 
 
     <td>Lorem Ipsum is simply dummy text of the printing and </td> 
 
     <td>It is a long established fact that a </td> 
 
    </tr> 
 
    <tr> 
 
     <td>Lorem Ipsum is simply dummy text of the printing and </td> 
 
     <td>It is a long established fact that a </td> 
 
    </tr> 
 
    </tbody> 
 
</table>

0
th, td {border: none; border-right: 1px solid black;} 
0

我覺得這是你找什麼:

table { 
    width: 85%; 
    border-collapse: collapse; 
    margin-left: 4%; 
    border: 1px solid black; 
} 
th { 
    text-align: left; 
    width: 50%; 
    border: 1px solid black; 
    padding: 5px 11px; 
    border-bottom: None; 
} 
td { 
    text-align: left; 
    width: 50%; 
    border: 1px solid black; 
    padding: 5px 11px; 
    border-top: None; 
} 
0

更新

https://jsfiddle.net/kac69ovn/1/

table { 
    width: 85%; 
    border-collapse: collapse; 
    margin-left: 4%; 
    border: 1px solid black; 
} 
th { 
    text-align: left; 
    width: 50%; 
    border-right: 1px solid black; 
    padding: 5px 11px; 
} 
td { 
    text-align: left; 
    width: 50%; 
    border-right: 1px solid black; 
    padding: 5px 11px; 
} 
1

保持你的桌子上滿邊界,但堅持border-leftborder-right爲您的thtd元素。

table { 
 
    width: 85%; 
 
    border-collapse: collapse; 
 
    margin-left: 4%; 
 
    border: 1px solid black; 
 
} 
 
th, td { 
 
    text-align: left; 
 
    width: 50%; 
 
    border-right: 1px solid black; 
 
    border-left: 1px solid black; 
 
    padding: 5px 11px; 
 
}
<table> 
 
     <tbody> 
 
      <tr> 
 
      <th>Firstname</th> 
 
      <th>Lastname</th> 
 
      </tr> 
 
      <tr> 
 
      <td>Lorem Ipsum is simply dummy text of the printing and </td> 
 
      <td>It is a long established fact that a </td> 
 
      </tr> 
 
     </tbody> 
 
    </table>