这是否可以通过CSS实现?

我在努力

tr.classname {
  border-spacing: 5em;
}

但没有用。也许我做错了什么?


当前回答

.table {
 border-collapse: separate; 
 border-spacing: 0 1rem;
}

这很适合我在表格之间提供垂直边距/间距。参考:https://www.w3docs.com/snippets/css/how-to-create-space-between-rows-in-the-table.html

其他回答

为表提供间距的正确方法是使用cellpadding和cellspacing,例如。

<table cellpadding="4">

执行上述操作。。。

table tr{ float: left width: 100%; }  tr.classname { margin-bottom:5px; } 

删除垂直列对齐方式,因此使用时要小心

要创建行间距的错觉,请将背景色应用于行,然后使用白色创建厚边框,以便创建“空间”:)

tr 
{
   background-color: #FFD700;
   border: 10px solid white;
}

我意识到这是对一个旧线程的回答,可能不是所要求的解决方案,但尽管所有建议的解决方案都没有达到我所需要的效果,但这个解决方案对我有效。

我有两个表格单元格,一个带有背景色,另一个带有边框色。上述解决方案删除了边界,因此右侧的单元格看起来像漂浮在半空中。成功的解决方案是用div和相应的类替换table、tr和td:table将是div id=“table_replacer”,tr将是div class=“tr_replaceer”,td将是div class=“td_replacer“(显然也将结束标记更改为div)

为了解决我的问题,css是:

#table_replacer{display:table;}
.tr_replacer {border: 1px solid #123456;margin-bottom: 5px;}/*DO NOT USE display:table-row! It will destroy the border and the margin*/
.td_replacer{display:table-cell;}

希望这对某人有所帮助。

好的,你可以

tr.classname td {background-color:red; border-bottom: 5em solid white}

确保背景色设置在td而不是行上。这应该适用于大多数浏览器。。。(铬,即已测试)