I am creating a kind of boardgame in javascript. The images for the board are put inside a table. I used to do this using html <table>
tags. However, I got convinced that due to the fact that this table does not really contain data, I should really use <div>
elements to visualize it.
<div id='board'>
<!-- the table starts here -->
<div class='mytable'>
<!-- table has multiple rows -->
<div class='myrow'>
<!-- a row has multiple cells -->
<div class='mycell'/>
...
</div>
...
</div>
</div>
To format them the same way a table would look, I am using the following CSS.
.mytable{
display:table;
width:auto;
border:0px;
border-spacing:0px;
padding: 0px;
border-collapse: collapse;
table-layout:fixed;
}
.myrow{
display:table-row;
width:auto;
height: auto;
clear:both;
}
.mycell{
float:left;/*fix for buggy browsers*/
text-align: center;
display:table-cell;
width:31px;
height:31px;
background: url(background.png) no-repeat;
}
Everything works fine on first sight. However when the table is too big to fit on the screen, then the entire cells start wrapping to the next line. This happens for example when I make the browser window smaller.
What I would like to happen, is that the cells just stay where they are, and move outside the view of the web browser. Or alternatively put them in a fixed sized container which shows scrollbars when the table is too big.
I tried to specify a constant width (e.g. width: 200px
) for the surrounding node (i.e. div#board
). But this only works if the width is bigger than the table (i.e. div.mytable
). (Unfortunately that's not the case, the table can have different sizes.)
What I tried:
overflow: scroll
doesn't work.white-space: nowrap
doesn't work.- also using
table-layout: fixed
but no visible difference. - tried
display: table-column
instead ofdisplay: table-cell
What am I missing ?