简体   繁体   English

表 tbody 将自身限制为 1 列的宽度

[英]Table tbody limits itself to 1 column's width

I'm currently working on a script generating a table from a database (to display elections results).我目前正在编写从数据库生成表格的脚本(以显示选举结果)。
I want some parts (for the primaries) to be collapsed (and only opened when clicking on a corresponding button).我希望某些部分(对于主要部分)折叠(并且仅在单击相应按钮时打开)。

Here is a part of the javascript code I'm using:这是我正在使用的 javascript 代码的一部分:

// Previous candidates in the loop
row +=
  '<tr><td colspan="3" style="text-align:center;" onclick="toggler(this.parentNode.parentNode.nextSibling);">';
row += PartyName(candidate.getAttribute("party")) + " primaries ▼"; // The display button
row += "</td></tr>";
row += '<tbody class="collapsible" style="display:block;">';
// Code running through the primaries candidates to display them
row += "</tbody>";
// Next candidates in the loop

The toggler function:切换器功能:

function toggler(item) {
  if (item.style.display == "none") {
    item.style.display = "block";
  } else {
    item.style.display = "none";
  }
}

Here is what the table currently looks like:这是该表目前的样子: tbody 中的所有内容只适合 1 列的宽度 The images on the left are not a problem (I just need to add them to the file).左边的图像没有问题(我只需要将它们添加到文件中)。 The problem, as you see, is that the tbody only fits in the width of 1 column.如您所见,问题在于 tbody 仅适合 1 列的宽度。 How do I fix this?我该如何解决?

我想为表格元素定义display: block会使典型的表格属性过时,所以我猜你应该使用height: 0height: auto而不是display: block/none ,还添加了overflow-y: hidden来切断高度为零时显示。

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

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