Search code examples
htmlcsscss-tables

Create table using div and CSS


I have div tags in below format:

<div>first</div>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>last</div>

I want it in 2X3(col X row) table. Is it possible? Only using CSS without adding any other HTML tag. If Yes, then what would be the CSS for that?

Output format:
first
1 4
2 5
3 6
Last

I want data in above format. Sorry I did not mention the format in above question.


Solution

  • You can use this css:

    .div-table{
      display:table;         
      width:auto;         
      background-color:#eee;         
      border:1px solid  #666666;         
      border-spacing:5px;/*cellspacing:poor IE support for  this*/
    }
    .div-table-row{
      display:table-row;
      width:auto;
      clear:both;
    }
    .div-table-col{
      float:left;/*fix for  buggy browsers*/
      display:table-column;         
      width:200px;         
      background-color:#ccc;  
    }