I want to create a simple isometric tilemap with HTML and CSS.
The tiles are 128px wide and 64px high, but some of them, like the one below, contains graphical elements that gives them a total height of 128px.
In this simplified example, the isometric tilemap is only 2x2 tiles and should look like this:
How do I display these tiles correctly with HTML and CSS, so that they have the right placement and proportions?
Please note that the 2x2 tilemap is just an example. The solution needs to work just as well (or just about) if the map is 5x5 tiles or 25x75 tiles. It also needs to work regardless of tile order.
So far, my idea has been to rotate the container to make it isometric, and then rotate the tiles in the opposite direction to "compensate" for the rotation of the container (I'd prefer to display the tiles the way they are drawn). But I'm not sure this is the right approach. The placement is not correct and the images are distorted.
Can you tell what I'm doing wrong?
.container {
width: 256px;
height: 256px;
transform: rotateX(60deg) rotateZ(45deg);
display: flex;
flex-wrap: wrap;
background-color: blue;
}
.tile {
width: 128px;
transform: rotateX(0deg) rotateZ(-45deg);
}
.grass {
height: 64px;
background-image: url("https://i.stack.imgur.com/39MxJ.png");
}
.bush {
height: 128px;
background-image: url("https://i.stack.imgur.com/GpNEI.png");
}
<div class="container">
<div class="tile grass"></div>
<div class="tile grass"></div>
<div class="tile bush"></div>
<div class="tile bush"></div>
</div>



