简体   繁体   English

CSS 表格样式 - 表格中心边框之间的间距

[英]CSS table style - spacing between center borders of table

I want a space between "a's measurement" right side border and "download b's" left side border along that column of borders but I am not sure what is needed because I am only aware of border-collapse .我想要在“a 的测量”右侧边框和“下载 b 的”左侧边框之间沿着该边框列留一个空格,但我不确定需要什么,因为我只知道border-collapse I just want something like a 2px-5px gap, just enough to tell there not the same measurement.我只想要一个 2px-5px 的差距,足以告诉那里不一样的测量。

JavaScript: JavaScript:

innerHTML = '<table class="tableRes" id="tableRes">\
    <thead><tr><th colspan="4">Test</th></tr></thead>\
    <tr><td>upload a</td><td>a's measurement</td><td>download b</td><td>b's measurement</td></tr>\
    <tr><td>upload c</td><td>c's measurement</td><td>download d</td><td>d's measurement</td></tr>\
    <tr><td>upload e</td><td>e's measurement</td><td>download f</td><td>f's measurement</td></tr>\
    <tr><td>upload g</td><td>g's measurement</td><td>download h</td><td>h's measurement</td></tr>\
    </table>';

CSS: CSS:

.tableRes {
  border: 1px solid black;
  border-collapse: collapse;
  background-color: #ADD8E6;
  margin-left: auto;
  margin-right: auto;
}
.th, td {
  border: 1px solid black;
}

You could insert an empty td in each row as a third cell and address that via css ( :nth-child(3) ) to have no border and a certain width:您可以在每一行中插入一个空的td作为第三个单元格,并通过 css ( :nth-child(3) ) 解决该问题,使其没有边框和一定的宽度:

 .tableRes { border: 1px solid black; border-collapse: collapse; background-color: #ADD8E6; margin-left: auto; margin-right: auto; } th, td { border: 1px solid black; } td:nth-child(3) { width: 15px; border: none; }
 <table class= "tableRes"> <thead> <tr> <th colspan="5">Test</th> </tr> </thead> <tr> <td>upload a</td> <td>a's measurement</td> <td></td> <td>download b</td> <td>b's measurement</td> </tr> <tr> <td>upload c</td> <td>c's measurement</td> <td></td> <td>download d</td> <td>d's measurement</td> </tr> <tr> <td>upload e</td> <td>e's measurement</td> <td></td> <td>download f</td> <td>f's measurement</td> </tr> <tr> <td>upload g</td> <td>g's measurement</td> <td></td> <td>download h</td> <td>h's measurement</td> </tr> </table>

td {
    padding: 2px 6px; //table elements doesn't get affected by margin
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM