My goal is to design a table layout with 4 columns, but only display 3 columns at a time. I plan to achieve this by using a div that spans the width of the 3 visible columns and applying overflow: hidden to hide the last column. When the button is clicked, I want the third column (company 2) to slide to the left and be replaced by the fourth column (company 3), enabling a comparison between company 1 and company 3. Upon clicking the button again, I expect company 3 to slide left and company 2 to slide in from the right, returning to their original positions. This feature is essential for mobile view where all columns cannot fit on the screen.
You can view the demo here: https://jsfiddle.net/smks/U7JHM/197/
HTML
<div class="div-table">
<div class="div-table-row header-row">
<div class="div-table-col header-row"> </div>
<div class="div-table-col header-row">company 1</div>
<div class="div-table-col header-row">company 2</div>
<div class="div-table-col header-row">company 3</div>
</div>
<div class="div-table-row">
<div class="div-table-col">Comparison 1</div>
<div class="div-table-col">yyy</div>
<div class="div-table-col">yyy</div>
<div class="div-table-col">yyy</div>
</div>
<div class="div-table-row">
<div class="div-table-col">Comparison 2</div>
<div class="div-table-col">yyy</div>
<div class="div-table-col">www</div>
<div class="div-table-col">yyy</div>
</div>
<div class="divRow">
<div class="div-table-col">Comparison 3</div>
<div class="div-table-col">uuu</div>
<div class="div-table-col">Mkkk</div>
<div class="div-table-col">yyy</div>
</div>
</div>
<br>
<button>Compare Next</button>
CSS
.div-table{
display:table;
width:auto;
border:1px solid #666666;
border-spacing:5px;/*cellspacing:poor IE support for this*/
padding: 0;
text-align: center;
}
.div-table-row{
display:table-row;
width:auto;
clear:both;
padding: 5px;
}
.div-table-col{
float:left;/*fix for buggy browsers*/
display:table-column;
width:200px;
border:1px solid #666666;
padding: 5px;
}
.header-row {
height: 50px;
}