javascript - How can I continue a 2 column HTML table to appear next to first x rows? - Stack Overflow

Say I've got an HTML table with two columns, with about 100 rows of data. I'd like to continu

Say I've got an HTML table with two columns, with about 100 rows of data. I'd like to continue the table next to itself after x rows.

It's currently displaying like this:

|head 1| head 2|
|------|-------|
|data 1| data 1|
|data 2| data 2|
 ...
|data 8| data 8|

What I'm trying to achieve is something like this:

|head 1| head 2||head 1| head 2|
|------|-------||------|-------|
|data 1| data 1||data 5| data 5|
|data 2| data 2||data 6| data 6|
|data 3| data 3||data 7| data 7|
|data 4| data 4||data 8| data 8|

My current solution is to just float two tables next to each other and split the data in the backend, but I'm sure there's a better way.

Say I've got an HTML table with two columns, with about 100 rows of data. I'd like to continue the table next to itself after x rows.

It's currently displaying like this:

|head 1| head 2|
|------|-------|
|data 1| data 1|
|data 2| data 2|
 ...
|data 8| data 8|

What I'm trying to achieve is something like this:

|head 1| head 2||head 1| head 2|
|------|-------||------|-------|
|data 1| data 1||data 5| data 5|
|data 2| data 2||data 6| data 6|
|data 3| data 3||data 7| data 7|
|data 4| data 4||data 8| data 8|

My current solution is to just float two tables next to each other and split the data in the backend, but I'm sure there's a better way.

Share Improve this question asked Mar 29, 2014 at 17:09 Jon BloomJon Bloom 1482 silver badges11 bronze badges 1
  • You can use tbody to group grows. You might try doing that and then setting tbody to display: table-cell to get them side by side. The only issue here is that im not sure if multiple thead elements within a single table are valid, so you might need to put the headers in each tbody i think to get them to display properly. Of course if you are still essentially splitting the data at some point on the backend to get it onto the respective groupings, the only thing this really gets you is having a single table. Fiddle: jsfiddle/H4pjx – prodigitalson Commented Mar 29, 2014 at 17:37
Add a ment  | 

2 Answers 2

Reset to default 5

You can change the defaut display: table; to inline-table;.

You can use a class like <table class="inline">.

table.inline  {
display:inline-table;
vertical-align:top; /* or else as your needs */
}

You can also try FLEXBOX for the same as follows

HTML

<div>
    <table>
        <tr>
            <td>Jill</td>
            <td>Smith</td>
            <td>50</td>
        </tr>
        <tr>
            <td>Eve</td>
            <td>Jackson</td>
            <td>94</td>
        </tr>
    </table>
    <table>
        <tr>
            <td>Jill</td>
            <td>Smith</td>
            <td>50</td>
        </tr>
        <tr>
            <td>Eve</td>
            <td>Jackson</td>
            <td>94</td>
        </tr>
    </table>
</div>

CSS

div {
     display: flex;
     flex-flow: row;
     justify-content: center;
 }
 table {
     border:1px solid red;
 }

Demo

Useful URLS:

  1. http://www.sketchingwithcss./samplechapter/
  2. http://css-tricks./snippets/css/a-guide-to-flexbox/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744793549a4594065.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信