Video wird geladen...

Video konnte nicht geladen werden

Zur Startseite

CSS Tip! ✨ Use CSS :has() on the :root to check for a condition on the page 🧐 For example, this pure CSS Minesweeper game 🤯 :root:has([id*="bomb"]:checked) body { --show-fail: 1; } If a bomb gets :checked, game over! 😭 CodePen.IO link below! 👇

55,548 Aufrufe • vor 3 Jahren •via X (Twitter)

10 Kommentare

Profilbild von jhey ▲🐻🎈
jhey ▲🐻🎈vor 3 Jahren

Here's that @CodePen link! 🚀 You'll need to be in a browser that supports CSS :has() to see this in action, ideally Chromium for full support 👀

Profilbild von jhey ▲🐻🎈
jhey ▲🐻🎈vor 3 Jahren

There's a little "trickery" here 🤫 I'm using JavaScript to generate the static game board. But, it would be cool to have something like @Netlify build out a new page each day with a different game 🤓 Here's the @CodePen with the JS generation ✨

Profilbild von jhey ▲🐻🎈
jhey ▲🐻🎈vor 3 Jahren

Side note: Don't drop this in production 😅 The a11y on it isn't great as with most "CSS only games". But, it's a rad experiment for pushing the limits with CSS :has() Got another one tomorrow that has some wild rules 😁 Stay tuned for that one!

Profilbild von jhey ▲🐻🎈
jhey ▲🐻🎈vor 3 Jahren

Also, if you wanna read all about CSS "@ property" which is used for this pure CSS timer, check out this article I wrote for @css ✨ It shows you how to build a pure CSS stopwatch 👀 And here's a pure CSS 3D stopwatch 👇 👉

Profilbild von TOMAZKI
TOMAZKIvor 3 Jahren

@CodePen :has( Firefox ) false

Profilbild von Darren Colson 🇬🇧
Darren Colson 🇬🇧vor 3 Jahren

@CodePen never thought of using has() on root for this purpose. gonna give myself a few hours tomorrow to test this puppy out. Thanks again for sharing.

Profilbild von Simon Ramsay 🚀 🧞‍♂️ 𝕩
Simon Ramsay 🚀 🧞‍♂️ 𝕩vor 3 Jahren

@CodePen What does --show-fail: 1; equate to? It seems like a Boolean of a var, so if your rule has() returns true then fail is true. But what does the var do?

Profilbild von jhey ▲🐻🎈
jhey ▲🐻🎈vor 3 Jahren

@CodePen In this demo, it reveals the losing "dialog"

Profilbild von Fernando Nuñez 💻
Fernando Nuñez 💻vor 3 Jahren

@CodePen @SaveToNotion #Thread #CSS

Profilbild von Ravi Kumar
Ravi Kumarvor 3 Jahren

@CodePen Great work, Jhey!

Ähnliche Videos