Different number of columns for each row

Davide R.

I'm not using the tag, so I can't use the colspan attribute.

I'd like to create a table with three cells in the first row, one cell in the last row and two cells in the other rows.

Here's my code (minimal):

.row {
    display: table-row;
}
.cell {
    display: table-cell;
}

HTML:

<div style="display: table;">
     <div class="row" style="width: 100%;">
            <div class="cell" style="width: 33% !important;">
                aaaa
            </div>
            <div class="cell" style="width: 33% !important;">
                bbbbb
            </div>
            <div class="cell" style="width: 33% !important;">
                ccccc
            </div>
      </div>
      <div class="row" style="width: 100%;">
            <div class="cell" style="width: 50% !important;">
                ddddd
            </div>
            <div class="cell" style="width: 50% !important;">
                eeeee
            </div>
      </div>
      <div class="row" style="width: 100%;">
            <div class="cell" style="width: 50% !important;">
                fffff
            </div>
            <div class="cell" style="width: 50% !important;">
                ggggg
            </div>
      </div>
      <div class="row" style="width: 100%;">
            <div class="cell" style="width: 100% !important;">
                last cell
            </div>
      </div>
</div>

And this is what I get (I can't post images): http://gyazo.com/cc036ed406f6c1a166955522d40e05b0.png

Marc Audet

I would build this layout as follows.

For the HTML:

<div class="parent">
     <div class="row r3">
            <div class="cell">aaaa</div>
            <div class="cell">bbbbb</div>
            <div class="cell">ccccc</div>
      </div>
      <div class="row r2">
            <div class="cell">ddddd</div>
            <div class="cell">eeeee</div>
      </div>
      <div class="row r2">
            <div class="cell">fffff</div>
            <div class="cell">ggggg</div>
      </div>
      <div class="row r1">
            <div class="cell">last cell</div>
      </div>
</div>

and apply the following CSS:

.row {
    display: table;
    border: 1px dashed blue;
    width: 100%
}
.cell {
    display: table-cell;
    border: 1px dotted blue;
}
.r3 .cell {
    width: 33.333333%;
}
.r2 .cell {
    width: 50%;
}
.r1 .cell {
    width: 100%;
}

Use display: table for each div.row block element with 100% width.

You don't need to explicitly define a CSS table row, one will be created anonymously as needed.

See reference: http://www.w3.org/TR/CSS2/tables.html#anonymous-boxes

See demo: http://jsfiddle.net/audetwebdesign/72yb5th2/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Create Different number of columns each row in a table with PHP and MYSQL

From Dev

GridView with Different Columns in Each row

From Dev

GridView with different number of columns according to the number of row

From Dev

Count number of columns by a condition (>) for each row

From Dev

count a character in each row and divide it into the number of columns

From Dev

Counting the number of columns below a value for each row

From Dev

Get different columns of each row from matrix

From Dev

R: how to change the number of columns in each row in facet_grid

From Dev

How to count the number of columns with a value on each row in python?

From Dev

Mathematica: Getting the minimum value in different columns for each row

From Dev

How to extract different columns from each row of a data.frame?

From Dev

Selecting different numbers of columns on each row of a data frame

From Dev

Mathematica: Getting the minimum value in different columns for each row

From Dev

import csv with different number of columns per row using Pandas

From Dev

How to change number of columns in a row for different display sizes

From Dev

SQL: Row number is different when sorting on columns with null values

From Dev

Add a different number of columns to dataframe depending on value from row in R

From Dev

SQL: Row number is different when sorting on columns with null values

From Dev

How to replace certain number of elements in each row (different for each row) with zero/NA in R dataframe?

From Dev

Comparing two dataframes of different length row by row and adding columns for each row with equal value

From Dev

R Calculate row average, different columns for each row as indicated by another column

From Dev

Selecting different elements of an R dataframe (one for each row, but possibly different columns) without using loops

From Dev

DataTables with different number of columns

From Dev

Union with different number of columns

From Dev

How to read the csv file properly if each row contains different number of fields (number quite big)?

From Dev

How to find number of rows that fall within a time period of each row, while satisfying criteria in other columns?

From Dev

R - How to count number of columns in each row of a file before reading the file

From Dev

Counting the number of columns greater than 0 for each row in SQL Server 2012

From Dev

Creating different columns with last 2 maxima in each row in a time series data in R

Related Related

  1. 1

    Create Different number of columns each row in a table with PHP and MYSQL

  2. 2

    GridView with Different Columns in Each row

  3. 3

    GridView with different number of columns according to the number of row

  4. 4

    Count number of columns by a condition (>) for each row

  5. 5

    count a character in each row and divide it into the number of columns

  6. 6

    Counting the number of columns below a value for each row

  7. 7

    Get different columns of each row from matrix

  8. 8

    R: how to change the number of columns in each row in facet_grid

  9. 9

    How to count the number of columns with a value on each row in python?

  10. 10

    Mathematica: Getting the minimum value in different columns for each row

  11. 11

    How to extract different columns from each row of a data.frame?

  12. 12

    Selecting different numbers of columns on each row of a data frame

  13. 13

    Mathematica: Getting the minimum value in different columns for each row

  14. 14

    import csv with different number of columns per row using Pandas

  15. 15

    How to change number of columns in a row for different display sizes

  16. 16

    SQL: Row number is different when sorting on columns with null values

  17. 17

    Add a different number of columns to dataframe depending on value from row in R

  18. 18

    SQL: Row number is different when sorting on columns with null values

  19. 19

    How to replace certain number of elements in each row (different for each row) with zero/NA in R dataframe?

  20. 20

    Comparing two dataframes of different length row by row and adding columns for each row with equal value

  21. 21

    R Calculate row average, different columns for each row as indicated by another column

  22. 22

    Selecting different elements of an R dataframe (one for each row, but possibly different columns) without using loops

  23. 23

    DataTables with different number of columns

  24. 24

    Union with different number of columns

  25. 25

    How to read the csv file properly if each row contains different number of fields (number quite big)?

  26. 26

    How to find number of rows that fall within a time period of each row, while satisfying criteria in other columns?

  27. 27

    R - How to count number of columns in each row of a file before reading the file

  28. 28

    Counting the number of columns greater than 0 for each row in SQL Server 2012

  29. 29

    Creating different columns with last 2 maxima in each row in a time series data in R

HotTag

Archive