简体   繁体   English

缩进表的每隔一行而不影响第一行。 HTML / CSS / JS / jQuery的

[英]Indenting every second row of a table without affecting the first rows. html/css/js/jQuery

I have a table full of data. 我有一个充满数据的表。 Every second row is a child row of every first row. 每隔一行是第一行的子行。 So each child row is hidden until I click the parent row. 因此,在单击父行之前,每个子行都是隐藏的。 The child rows then fadeIn below the parents with jQuery. 然后使用jQuery将子行淡入父母的下方。

How would I indent the child rows beneath the parent rows so they are clearly child nodes to the parents? 我如何缩进父行下面的子行,以便它们显然是父节点的子节点?

Ive tried adding small elements to the child rows but that just doesnt look right. 我曾尝试在子行中添加小元素,但这看起来并不合适。 It ends up crushing the first rows when I expand out the second rows. 当我展开第二行时,它最终会压碎第一行。

I hope this doesnt sound like jibberish... 我希望这听起来不像是胡言乱语......

//HTML & CSS
<table>
    <tr>
        <th id="clickDiv3"></th>
        <th>Firstname</th>
        <th>Lastname</th>
    </tr>
    <tr>
       <th></th>
       <td class="showThird">Peter</td>
       <td class="showThird">Griffin</td>
    </tr>
    <tr>
       <th></th>
       <td class="showThird">Lois</td>
       <td class="showThird">Griffin</td>
    </tr>
</table>


  //JS
  $("#clickDiv3").click(function(){
      $(".showThird").slideDown(".500").fadeIn(".200");
  });

Any help or advice would be very appreciated! 任何帮助或建议将非常感谢!

Actually you can't exactly do that with tables but you can try this: 实际上你不能用表完全做到这一点,但你可以试试这个:

table tr:nth(3) td {
    padding-left : 10px;
}

But if you don't have so many columns, you can simply use ul instead of table for such usage. 但是如果你没有这么多列,你可以简单地使用ul而不是table来实现这种用法。 Take a look at http://cssdeck.com/labs/pure-css-tree-menu-framework 请查看http://cssdeck.com/labs/pure-css-tree-menu-framework

Not sure if this works cross-browser (only tested in Chrome). 不确定这是否适用于跨浏览器(仅在Chrome中测试过)。 All cells on even rows will be indented (and overflow the table width): 偶数行上的所有单元格都将缩进(并溢出表格宽度):

tr:nth-child(2n) td {
    position: relative;
    left: 20px;
}

http://jsfiddle.net/3KJdX/ http://jsfiddle.net/3KJdX/

But you should listen to the advice the other users are giving you: maybe a table is not the right structure for your data. 但您应该听取其他用户给您的建议:表格可能不是您数据的正确结构。

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

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