TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Building a Hexagonal Grid in CSS

242 pointsby indentitalmost 5 years ago

13 comments

josephwegneralmost 5 years ago
This is a must read if you&#x27;re working with hex grids: <a href="https:&#x2F;&#x2F;www.redblobgames.com&#x2F;grids&#x2F;hexagons&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.redblobgames.com&#x2F;grids&#x2F;hexagons&#x2F;</a>
评论 #23582291 未加载
评论 #23586144 未加载
评论 #23582183 未加载
评论 #23581601 未加载
danellisalmost 5 years ago
I see a lot of convoluted CSS things like this. Is there not much awareness of SVG in the webdev community, or is there some other reason people don&#x27;t want to use it?
评论 #23579065 未加载
评论 #23579711 未加载
评论 #23580245 未加载
评论 #23578980 未加载
mmanfrinalmost 5 years ago
Oooh, nice.<p>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 &#x2F; <a href="https:&#x2F;&#x2F;konvajs.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;konvajs.org&#x2F;</a>) which was pretty easy to implement.<p>One completed (albeit ugly) project was an implementation of a minigame I played in Magnum Opus:<p><a href="https:&#x2F;&#x2F;game.manfrincdn.com&#x2F;#&#x2F;" rel="nofollow">https:&#x2F;&#x2F;game.manfrincdn.com&#x2F;#&#x2F;</a><p>It&#x27;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&#x27;ve ended up often hitting lower level APIs to watch&#x2F;update&#x2F;rerender parts, but at that point I feel like I end up reimplementing parts of vue within itself, and that nagging &#x27;you are missing an obvious solution&#x27; worm starts up.<p>A pure CSS approach would make this a lot simpler, because there&#x27;d be no need to do any manual wiring up of state to canvas state, you&#x27;d just let vue handle that cycle because that&#x27;s its core competency.
评论 #23581157 未加载
greencorealmost 5 years ago
Impressive! It&#x27;s interesting for me if such grade CSS developers get same compensation as their JavaScript counterparts.
评论 #23578938 未加载
pugworthyalmost 5 years ago
Kind of a nostalgia thing to see this, as one of my earliest answers on gamedev stack was about creating a hex map (See <a href="https:&#x2F;&#x2F;gamedev.stackexchange.com&#x2F;questions&#x2F;6382&#x2F;how-to-create-a-hexagon-world-map-in-php-from-a-database-for-a-browser-based-str" rel="nofollow">https:&#x2F;&#x2F;gamedev.stackexchange.com&#x2F;questions&#x2F;6382&#x2F;how-to-crea...</a>)<p>I cheated and used hex-shaped png files but looking back using CSS to just auto-shape the PNG would be good.<p>That said, if you ARE using textures in the hexes and you&#x27;d like to actually tile them, you&#x27;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.
评论 #23580642 未加载
bynormousalmost 5 years ago
PSA: don&#x27;t open this on Safari on a Mac book Pro, it&#x27;ll either take a while to load or it&#x27;ll freeze your computer if you have other heavy processes running. Chrome works fine.
juancaalmost 5 years ago
I would like to see this where each edge is also uniquely addressable.
cheeaunalmost 5 years ago
This totally reminded me of Tantek&#x27;s site <a href="http:&#x2F;&#x2F;tantek.com&#x2F;map.html" rel="nofollow">http:&#x2F;&#x2F;tantek.com&#x2F;map.html</a><p>Wayback: <a href="http:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20020321021851&#x2F;http:&#x2F;&#x2F;tantek.com&#x2F;map.html" rel="nofollow">http:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20020321021851&#x2F;http:&#x2F;&#x2F;tantek.com&#x2F;...</a>
waisbrotalmost 5 years ago
Why would you make this responsive? It doesn&#x27;t make sense for any games to have the map&#x2F;board be different based on window-size.
_Microftalmost 5 years ago
I ran into the problem too that CSS-counters are strings and not integers. Can anyone explain the reasoning? It&#x27;s understandable that the displayed value is a string but the (sub)counters themselves could as well been done as integers imo.
CGamesPlayalmost 5 years ago
Can anybody explain to me why I would use the CSS grid to accomplish this and not negative margins on inline divs? The latter is how I immediately guessed that this would be implemented. What would be the advantages of the grid method?
评论 #23581669 未加载
gerdesjalmost 5 years ago
I&#x27;m a bystander that ploughed through quite a lot of text regarding one case.<p>How do you do ngon grids in CSS?
评论 #23580236 未加载
terrycodyalmost 5 years ago
Sry noob here, but are there any spaces you have to use this hexagonal grid to solve things?
评论 #23627580 未加载