Correct table layout generation with CSS: unexpected cells shift
Posted
by MrG
on Stack Overflow
See other posts from Stack Overflow
or by MrG
Published on 2010-03-17T09:43:43Z
Indexed on
2010/03/17
9:51 UTC
Read the original article
Hit count: 295
I'm trying to generate a dynamic table using CSS:
<html>
<head>
<style>
div.el1, div.el2 {
color:white;
width:70px;height:70px;
border:0px;
padding:0px;
font-size: 10px;
font-family: "Courier";
}
div.el1 {
background-color: green;
}
div.el2 {
background-color: orange;
}
div.tablediv {
display: table;
border:0px;
border-spacing:0px;
border-collapse:separate;
}
div.celldiv {
display: table-cell;
}
div.rowdiv {
display: table-row;
width:auto;
}
</style>
</head>
<body>
<div class="tablediv">
<div class="rowdiv">
<div class="celldiv">
<div class="el1" id="x1y1">ABC</div>
</div>
<div class="celldiv">
<div class="el2" id="x1y2"></div>
</div>
</div>
<div class="rowdiv">
<div class="celldiv">
<div class="el1" id="x2y1"></div>
</div>
<div class="celldiv">
<div class="el1" id="x2y2"></div>
</div>
</div>
</div>
</body>
</html>
The content of body is dynamically generated and should be displayed as a table. Unfortunately, each cell shifts down if it contains data:
expected reality
--- --- --- ---
| | | | | |
--- --- |ABC|---
| | | | | |
--- --- --- ---
| | |
--- ---
I'm grateful for any help. Many thanks!
© Stack Overflow or respective owner