这是否可以通过CSS实现?

我在努力

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

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


当前回答

你可以在桌子上做一些事情:

table {
  border-collapse: separate;
  border-spacing: 0 15px;
}

table selected:因为它将选择所有表,所以如果您想选择单个表,也可以这样做

<table class="res">

</table>

对于上面的html,您可以这样做,请注意,对于特定的表,如果需要,可以使用下面的方法。

.res {
      border-collapse: separate;
      border-spacing: 0 15px;
    }

参考:https://www.w3docs.com/snippets/css/how-to-create-space-between-rows-in-the-table.html

其他回答

回答太晚了:)

如果将float应用于tr元素,则可以使用margin属性在两行之间设置空格。

table tr{
float: left
width: 100%;
}

tr.classname {
margin-bottom:5px;
}

我在与一个类似的问题作斗争时偶然发现了这一点。我发现Varun Natraaj的答案非常有用,但我会使用透明边框。

td { border: 1em solid transparent; }

透明边框仍具有宽度。

好的,你可以

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

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

在这里,这项工作很顺利:

#myOwnTable td { padding: 6px 0 6px 0;}

我想,如果需要的话,您可以通过指定哪个td来实现更细粒度的布局。

你可以在桌子上做一些事情:

table {
  border-collapse: separate;
  border-spacing: 0 15px;
}

table selected:因为它将选择所有表,所以如果您想选择单个表,也可以这样做

<table class="res">

</table>

对于上面的html,您可以这样做,请注意,对于特定的表,如果需要,可以使用下面的方法。

.res {
      border-collapse: separate;
      border-spacing: 0 15px;
    }

参考:https://www.w3docs.com/snippets/css/how-to-create-space-between-rows-in-the-table.html