Building a Hexagonal Grid in CSS
ninjarockstar.dev
ninjarockstar.dev
I put an SVG background, then layer the HTML over it.
It works but, I'm not happy about it.
https://developer.mozilla.org/en-US/docs/Web/SVG/Element/for...
It seems the web community is dedicated to forcing things to work until they become fully supported features of HTML.
Also, in this case, CSS grid is a very good choice for layout, but the background could totally just be an svg.
SVG is great as something to embed in HTML, but not the other way around.
I have worked with hexes in little side project games, it was a difficult process and I went through a phase of trying to home-roll canvas drawing of hexes (and making some interesting looking bugs). I ended up using a js library (Konva / https://konvajs.org/) which was pretty easy to implement.
One completed (albeit ugly) project was an implementation of a minigame I played in Magnum Opus:
https://game.manfrincdn.com/#/
It's been a little project kicking around that I want to make a hex game engine of sorts in Vue. The difficult part I keep running in to is connecting the state of the engine (in vue) with the state of the canvas (outside). I've ended up often hitting lower level APIs to watch/update/rerender parts, but at that point I feel like I end up reimplementing parts of vue within itself, and that nagging 'you are missing an obvious solution' worm starts up.
A pure CSS approach would make this a lot simpler, because there'd be no need to do any manual wiring up of state to canvas state, you'd just let vue handle that cycle because that's its core competency.
One problem I remember running in to (drawing hexes) is that the redraw of one hex overwrote what had been drawn in another, causing corners of the bounding box of a hex to clear its neighbors. Did you run in to any issues like that, or was that likely just a quirk of how I coded it (I am amateur with canvas, so it's a likely cause).
I cheated and used hex-shaped png files but looking back using CSS to just auto-shape the PNG would be good.
That said, if you ARE using textures in the hexes and you'd like to actually tile them, you'll have to explicitly design an image that will tile. So you might as well just create hex shaped images like this and forget getting too fancy.
Wayback: http://web.archive.org/web/20020321021851/http://tantek.com/...
How do you do ngon grids in CSS?
N-gon grids don't make sense for N other than 3, 4, and 6 [1]. N=4 is easy, N=6 is in the OP. I suspect one could find a similar "css trick" for N=3.
1: https://en.wikipedia.org/wiki/List_of_regular_polytopes_and_...