[英]How can I separate columns of a table in html?
I want to separate columns of a table, adding a gap between them like the image, but the best I have gotten was to separate ALL columns of a table ( https://www.w3schools.com/cssref/tryit.asp?filename=trycss_border-spacing ), and I just want separate specific columns, for example separating a table of 10 columns in 4-2-2-2.我想分隔表的列,像图像一样在它们之间添加一个间隙,但我得到的最好的方法是分隔表的所有列( https://www.w3schools.com/cssref/tryit.asp?filename =trycss_border-spacing ),我只想要单独的特定列,例如在 4-2-2-2 中分隔一个 10 列的表。
This is what I want to achieve.这就是我想要实现的。
And this is best I have goten with border-collapse: separate;这是我用border-collapse得到的最好的:分开; and border-spacing: 15px 0px;和边框间距:15px 0px; ( https://www.w3schools.com/cssref/tryit.asp?filename=trycss_border-spacing ) ( https://www.w3schools.com/cssref/tryit.asp?filename=trycss_border-spacing )
table tr th:nth-child(4){ padding-right: 50px; } table tr th:nth-child(6){ padding-right: 50px; } table tr th:nth-child(8){ padding-right: 50px; } table tr th { background-color: lightgray; }
<table> <tr> <th>TH</th> <th>TH</th> <th>TH</th> <th>TH</th> <th>TH</th> <th>TH</th> <th>TH</th> <th>TH</th> <th>TH</th> <th>TH</th> </tr> <tr> <td>TD1</td> <td>TD1</td> <td>TD1</td> <td>TD1</td> <td>TD1</td> <td>TD1</td> <td>TD1</td> <td>TD1</td> <td>TD1</td> <td>TD1</td> </tr> <tr> <td>TD2</td> <td>TD2</td> <td>TD2</td> <td>TD2</td> <td>TD2</td> <td>TD2</td> <td>TD2</td> <td>TD2</td> <td>TD2</td> <td>TD2</td> </tr> <tr> <td>TD3</td> <td>TD3</td> <td>TD3</td> <td>TD3</td> <td>TD3</td> <td>TD3</td> <td>TD3</td> <td>TD3</td> <td>TD3</td> <td>TD3</td> </tr> </table>
You can separate columns by using padding as @StackSlave suggested in the comments.您可以使用注释中建议的@StackSlave 填充来分隔列。
But furthermore, you can target nth-child
elements, as seen in my CSS, to break the table up into columns, ie 10 columns becomes 4-2-2-2但此外,您可以定位nth-child
元素,如我的 CSS 中所见,将表格分成列,即 10 列变为 4-2-2-2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.