简体   繁体   English

如何使用CSS在HTML中的单元格之间的边框间距中填充颜色

[英]How to fill color in border spacing between cells in HTML using CSS

I'm trying to fill black color between vertical cell spacing(columns) of a table in html but can't figure it out how to do it.我正在尝试在 html 中表格的垂直单元格间距(列)之间填充黑色,但不知道该怎么做。 Here is my code这是我的代码


 table, th, td { border-collapse: separate; border-spacing: 2px; border-style: solid; border-width: thin; }
 <table> <tr> <th>Heading One</th> <th>Heading Two</th> <th>Heading Three</th> </tr> <tr> <td>Apple</td> <td>10</td> <td>$1.0</td> </tr> <tr> <td>Mango</td> <td>12</td> <td>$2.0</td> </tr> </table>

Best way to do this would be to add a background color to the table and a foreground color to the fields.最好的方法是为表格添加背景色,为字段添加前景色。 See below见下文

 table, th, td { border-collapse: separate; border-spacing:2px; border-style: solid; border-width:thin; } table{background:#000;} tr{background: #fff;}
 <table> <tr><th>Heading One</th> <th>Heading Two </th> <th>Heading Three </th> </tr> <tr> <td>Apple</td> <td>10</td> <td>$1.0</td> </tr> <tr> <td>Mango</td> <td>12</td> <td>$2.0</td> </tr> </table>

The space between the cells is the table.单元格之间的空间是表格。 You change the background of the table in the same way as any other element.您可以像更改任何其他元素一样更改表格的背景。

Watch out, the default background colour of the table cells is transparent.注意,表格单元格的默认背景颜色是透明的。

 table, th, td { border-collapse: separate; border-spacing: 2px; border-style: solid; border-width: thin; } table { background-color: black; } td, th { background-color: white; }
 <table> <tr> <th>Heading One</th> <th>Heading Two</th> <th>Heading Three</th> </tr> <tr> <td>Apple</td> <td>10</td> <td>$1.0</td> </tr> <tr> <td>Mango</td> <td>12</td> <td>$2.0</td> </tr> </table>

From another approach, the border-collapse doesn't have to be separated, collapse value also works.从另一种方法来看, border-collapse不必分开,折叠值也有效。 The size of the border can be changed by changing the value of border-width .可以通过更改border-width的值来更改border-width

 table, th, td { border-collapse: collapse; border-width: 4px; border-style: solid; border-color: #000; } tr{background: #eee;}
 <table> <tr> <th>Heading One</th> <th>Heading Two</th> <th>Heading Three</th> </tr> <tr> <td>Apple</td> <td>10</td> <td>$1.0</td> </tr> <tr> <td>Mango</td> <td>12</td> <td>$2.0</td> </tr> </table>

Updated on May 13th, 2021 2021 年 5 月 13 日更新

As I have read through the book CSS Mastery Advanced Web Standards Solution, 3rd 3, the book has mentioned in ch9 that using border-collapse: collapse;正如我读过的书 CSS Mastery Advanced Web Standards Solution, 3rd 3,这本书在 ch9 中提到使用border-collapse: collapse; can result empty spacing on vertical border using IE/Edge.使用 IE/Edge 可能会在垂直边框上产生空白间距。

Add the below css and try,添加以下css并尝试,

 table, th, td
{
  border-collapse: separate;
    border-spacing:2px;
    border-style: solid;
    border-width:thin;    
    background-color:White;    
}
table
{
  background-color:Black;
}

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

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