Загрузка видео...

Не удалось загрузить видео

На главную

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 просмотров • 3 лет назад •via X (Twitter)

Комментарии: 10

Фото профиля jhey ▲🐻🎈
jhey ▲🐻🎈3 лет назад

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 👀

Фото профиля jhey ▲🐻🎈
jhey ▲🐻🎈3 лет назад

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 ✨

Фото профиля jhey ▲🐻🎈
jhey ▲🐻🎈3 лет назад

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!

Фото профиля jhey ▲🐻🎈
jhey ▲🐻🎈3 лет назад

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 👇 👉

Фото профиля TOMAZKI
TOMAZKI3 лет назад

@CodePen :has( Firefox ) false

Фото профиля Darren Colson 🇬🇧
Darren Colson 🇬🇧3 лет назад

@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.

Фото профиля Simon Ramsay 🚀 🧞‍♂️ 𝕩
Simon Ramsay 🚀 🧞‍♂️ 𝕩3 лет назад

@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?

Фото профиля jhey ▲🐻🎈
jhey ▲🐻🎈3 лет назад

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

Фото профиля Fernando Nuñez 💻
Fernando Nuñez 💻3 лет назад

@CodePen @SaveToNotion #Thread #CSS

Фото профиля Ravi Kumar
Ravi Kumar3 лет назад

@CodePen Great work, Jhey!

Похожие видео