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!
EDIT:
adding vertical-align: middle; to div.celldiv fixed the problem, yet I don't understand the reasons. Especially since the content is still aligned to the top of the cell.