简体   繁体   English

使用CSS将多个连续的行单元归为一组?

[英]Group multiple consecutive row cells into one with CSS?

Ok, here's a graphic to explain what I'm talking about: 好的,这是一张图形来解释我在说什么:

这就是我当前的表格

这就是我希望桌子看起来像的样子

The first table would be what my html currently produces and the second table is what I'd like it to produce. 第一个表是我的html当前生成的内容,第二个表是我希望它生成的内容。

 #animalTable{ display: table; } .animalRow{ display: table-row; } .animalCell{ display: table-cell; width: 33%; } 
 <div id="animalTable"> <div class="animalRow"> <div class="animalCell">Dog</div> <div class="animalCell">Milton</div> <div class="animalCell">1/2/1998</div> </div> ... </div> 

What would be the best/easiest way to get my desired table? 拿到我想要的桌子的最好/最简单的方法是什么? I know I could brute force it by creating sub-tables inside the main table but I was wondering if there was a better way? 我知道可以通过在主表内创建子表来强行使用它,但我想知道是否有更好的方法?

Also, sorry if this is a dumb question. 另外,如果这是一个愚蠢的问题,对不起。

I suggest using tables instead of div for this specific case. 对于这种特定情况,我建议使用tables而不是div Here is why you should Use tables for what they are meant to and div's for what they are meant to . 这就是为什么您应该将表用于其含义,将div用于其含义

What you are looking for is called Colspan and Rowspan , both are HTML td and th attributes. 您要查找的是ColspanRowspan ,它们都是HTML tdth属性。

Example: 例:

<table>
  <tr>
    <th>Month</th>
    <th>Savings</th>
    <th>Savings for holiday!</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
    <td rowspan="2">$50</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>

You can read further on w3schools . 您可以在w3schools上进一步阅读。

Hope this helps. 希望这可以帮助。

Simple, add different class or id selectors and in the css, remove all borders and re-add the ones you want to keep. 很简单,添加不同的类或id选择器,然后在CSS中删除所有边框,然后重新添加要保留的边框。 Example, 例,

div{
border: none;
border-top: solid 1px black;
border-left: solid 1px black;
}

Correct me if I am misunderstanding. 如果我误会了,请纠正我。 Otherwise, if you have any questions don't hesitate to ask! 否则,如果您有任何疑问,请随时提出!

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

相关问题 如何突出显示/悬停/单击HTML表格中选定的一组连续行单元格 - How to highlight/hover/click a selected group of consecutive row cells in HTML table 一个元素可以占据一个 CSS 网格行而一个子元素占据该行的一个单元格吗? - Can an element occupy one CSS grid row and a subelement occupy one of the row's cells? 是否可以使用Bootstrap将多个控制组放在一行中 - is it possible to have multiple control-group in one row with Bootstrap 将一行单元格拆分为多行 - Split a row of cells into multiple rows 如何通过在 Bootstrap 中的一行的一侧放置多个按钮来修复 CSS? - How to fix CSS with placing multiple buttons on one side of a row in Bootstrap? 如何使用jquery将css逐行添加到多个div中 - how to add css to multiple divs in a row and one after another with jquery 具有多个GROUP BY的MySQL查询-如何在HTML表格中将一组设为列头,一组设为行头? - MySQL Query with multiple GROUP BY - How do I make one group a column head and one group a row head in an HTML table? CSS hover 在除某些单元格之外的表格行上 - CSS hover on a table row with the exception of some cells 由tbody元素建立的行组的第2行上没有任何单元格 - Row 2 of a row group established by a tbody element has no cells beginning on it 使一列单元格确定行高 - Make one column of cells determine row height
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM