Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How DIV & CSS work with Rowspan & Colspan?

I have studied few days about how to use div to create table cells and merge cells, Actually I can did this with TABLE, but can't do the same screen result in DIV, hope someone can help me drive me the better method or fix the code.

Actually, I want to make all the cells in same Width and Height (Except the Merged Area) in the full screen mode, but the problem was the merged cell at center. I tried many methods cannot make it working like the TABLE style.

Here is the result I want, but make with table:

<style>
html, body{
    width:100%;
    height:100%;
    margin:0;
    padding:0;
}
table {
    border-width: 1px 1px 0px 0px;
    border-spacing:0;
    margin:0;
    padding:0;
    width: 100%;
    height: 100%;
}
td { 
    border-width: 0px 0px 1px 1px;
}
table, td {
    border-style: solid;
    border-color: purple;
}
.w25 {
    width:25%;
    height:25%;
}
.w50 {
    width:50%;
    height:50%;
}
.w100 {
    width:100%;
    height:100%;
}
</style>
<table class='w100'>
    <tr>
        <td class='w25'>D</td>
        <td class='w25'>E</td>
        <td class='w25'>F</td>
        <td class='w25'>G</td>
    </tr>
    <tr>
        <td class='w25'>C</td>
        <td class='w50' colspan=2 rowspan=2 >MERGED AREA</td>
        <td class='w25'>H</td>
    </tr>
    <tr>
        <td class='w25'>B</td>
        <td class='w25'>I</td>
    </tr>
    <tr>
        <td class='w25'>A</td>
        <td class='w25'>L</td>
        <td class='w25'>K</td>
        <td class='w25'>J</td>
    </tr>
</table>

And this is the code I currently making for DIV version, but no success to balanced all the the width and height in full screen.

<style>
html, body{
    width:100%;
    height:100%;
    margin:0;
    padding:0;
}
.table {
    border-width: 1px 1px 0px 0px;
}
.intable {
    border-width: 0px 1px 0px 0px;
}
.table, .intable {
    display:table;
    width:100%;
    height:100%;
}
.cell {
    display:table-cell;
}
.row {
    display:table-row;
}
.cell {
    border-width: 0px 0px 1px 1px;
    width:25%;
}
.table, .intable, .cell {
    border-style: solid;
    border-color: purple;
}
</style>
<div class='table'>
    <div class='row'>
        <div class='cell' style="max-width:25%;">D</div>
        <div class='intable'>
            <div class='cell'>E</div>
            <div class='cell'>F</div>
        </div>
        <div class='cell'>G</div>
    </div>
    <div class='row'>
      <div class='intable'>
        <div class='row'>
          <div class='cell'>C</div>
        </div>
        <div class='row'>
          <div class='cell'>B</div>
        </div>
      </div>
      <div class='cell'>Merged Area</div>
      <div class='intable'>
        <div class='row'>
          <div class='cell'>H</div>
        </div>
        <div class='row'>
          <div class='cell'>I</div>
        </div>
      </div>
    </div>
    <div class='row'>
        <div class='cell'>A</div>
        <div class='intable'>
            <div class='cell'>L</div>
            <div class='cell'>K</div>
        </div>
        <div class='cell'>J</div>
    </div>
</div>

Table Version JSFiddle

DIV Version JSFiddle

Wish somebody can fix the code!

like image 956
Andy Cheng Avatar asked Feb 24 '17 12:02

Andy Cheng


1 Answers

Try adding another class to your merged column, like so:

<div class='cell merged'>Merged Area</div>

and change the css of the merged area, like so:

.merged{
    width:50%;
    height:50%;
}

The reason I did this is because you had the same class on your merged area, but you wanted the size to take up double the space of a normal cell. So all I did was add an additional class changing the width and height of the merged area to get the desired result.

Here is an updated Fiddle:

https://jsfiddle.net/6hx2uooz/4/

like image 140
manneJan89 Avatar answered Oct 02 '22 01:10

manneJan89