Normally, the connection between CSS and HTML is that CSS selectors match HTML elements, and the CSS styles them. CSS doesn't know about the actual content in the HTML. But there is a way CSS can get its hands on data in HTML, so long as that data is within an attribute on that HTML element.
I came across a couple such animations a while ago and this gave me the idea of creating my own versions with as little code as possible, no external libraries, using various methods, some of which take advantage of more recent features we can use these days, such as CSS variables. This article is going to guide you through the process of building these demos.
One thing that single
div pieces rarely do is animate. If you can transform your
div or one of its pseudo elements, that's fair (as Lynn Fisher does with her fantastic BB-8). But you cannot directly change the
transform of the individual "elements" you create inside your
div, since they are not actual DOM elements.
I am a big believer of trying something a little different and interesting to learn tools you otherwise might never learn. Working with the constraints of a single
div might not be great for production work, but it can be a great exercise (and challenge) to stretch your skills in a fun way. In that spirit, we'll use this technique to explore how Custom Properties (CSS Variables) work and even provide us a path to animation inside our
I know there are a ton of pure CSS cube tutorials out there. I've done a few myself. But for mid-2017, when CSS Custom Properties are supported in all major desktop browsers, they all feel... outdated and very WET. I thought I should do something to fix this problem, so this article was born. It's going to show you the most efficient path towards building a CSS cube that's possible today, while also explaining what common, but less than ideal cube coding patterns you should steer clear of. So let's get started!
CSS has Custom Properties now. We've written about them a bunch lately. Browser support is good, but of course, old non-evergreen browsers like Internet Explorer don't have them and never will. I can see the appeal of authoring with "future CSS", and letting a preprocessor backport it to CSS that is compatible with older browsers. Babel for CSS! Why not?!
It makes me nervous though - because it's only some use cases of Custom Properties that you can preprocess. There are plenty of situations where what you are doing with a Custom Property just isn't possible to preprocesses. So if you do, you're putting yourself in a pretty weird situation.
Most of the power comes from two unique abilities of Custom Properties:
- The cascade
Even more power is exposed as you combine Custom Properties with other preexisting CSS concepts, like
Cool, right? But still, how actually useful is that? What are the major use cases? I think we're still seeing those shake out.
One use case, it occurred to me, would be theming of a site (think: custom colors for elements around a site). (more…)
CSS Custom Properties give us the ability to reach into a property value and change certain parts of it. That's useful in a bunch of places, but in particular, it's useful in properties which don't allow us to do it any other way.