Add Opacity to an Existing Color (by Chris Coyier)
Applying opacity to an existing colour value is a pretty common design requirement, and here Chris presents five ways to achieve it.
Hi, I’m Laurence. I’m a Glaswegian web developer using modern web standards to create user-focused, responsive websites. I also make music, play records and ping pongs. This is my online home; a playground for coding fun and place to share thoughts on the web, music and more.
Applying opacity to an existing colour value is a pretty common design requirement, and here Chris presents five ways to achieve it.
My latest radio show is dedicated to Ryuichi Sakamoto, who sadly died recently. I played a couple of tracks by the great man alongside more of my favourite music.
Two lovely new websites (or website updates) appeared on my radar this last week that I wanted to note here for future front-end inspiration.
Vitaly Friedman’s Smart Interface Patterns has had some lovely animation and component work from Clearleft alumni Cassie Evans and Trys Mudford. Given Vitaly’s obsession with creating accessible, user-friendly components and the collaborators he has on board, I expect this site to be choc-full of well crafted nuggets for reference! It looks ace, too.
I noted a while ago that the W3C had a new Design System, and now the W3C has a new website in beta too. I imagine it might use components from that Design System alongside other carefully-considered patterns of markup, style and behaviour.
Nice job on these sites, to all concerned!
In responsive design we generally want a single component to get different styles in different contexts. Up until recently the prevailing method of context-awareness was to use a CSS media query to query the viewport size. This wasn’t ideal. For example you might want an component to be styled differently when in a narrow context such as a sidebar (regardless of the device size), and viewport-based queries don’t help with that.
But everything has changed. We can now use CSS to query the size of any given container and this feature is supported in all major browsers.
There’s a bit of new syntax to learn, so I recently had my first play with container queries on codepen.
My pen is pretty trivial, but the goal was specifically to do the most minimal test that lets me test-drive the key syntax. It turns out that it’s quite straightforward.
Define an element as a container:
.sidebar {
container: ctr-sidebar / inline-size;
}
Change the styles of another element (.foo
) when it’s inside that container and the container’s inline-size (the logical property name for width
) matches a given query:
@container ctr-sidebar (max-width: 300px) {
.foo {
// context-specific styles go here
}
}
Note that you could also omit the ctr-sidebar
context in the above query, if you wanted the change to apply in all defined containers.
I’m a fan of web designers and developers collaborating closely rather than designers throwing mock-ups over the wall. Recently I read two newsletters relating to this topic, or perhaps more accurately about perceived divisions between design and development and some better, more modern ways of thinking.