Search
24.6.2024
CSS Meditation #6: The color space is always calc(rgb(0 255 0)+er) on the other side of the fence.…
originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter
Efficient Infinite Utility Helpers Using Inline CSS Custom Properties and calc()
6.8.2021
I recently wrote a very basic Sass loop that outputs several padding and margin utility classes. Nothing fancy, really, just a Sass map with 11 spacing values, looped over to create classes for both padding and margin on each side. …
The post Efficient Infinite Utility Helpers Using Inline...
Of Course We Can Make a CSS-Only Clock That Tells the Current Time!
16.7.2021
Let’s build a fully functioning and settable “analog” clock with CSS custom properties and the calc() function. Then we’ll convert it into a “digital” clock as well. All this with no JavaScript!
Here’s a quick look at the clocks …
The post Of Course We Can Make a CSS-Only Clock That Tells...
The Raven Technique: One Step Closer to Container Queries
10.11.2020
For the millionth time: We need container queries in CSS! And guess what, it looks like we’re heading in that direction.
When building components for a website, you don’t always know how that component will be used. Maybe it will be render as wide as the browser window is. Maybe two of them...
Announcing the 2020 State of CSS Survey
20.10.2020
Last year’s State of CSS Survey yielded interesting results. There’s the quick adoption of features, like calc() and CSS custom properties. There’s also the overwhelming opinion that CSS is fun to write even as we see a growing reliance on CSS-in JS. We also saw some predictable...
Animating Number Counters
9.10.2020
Number animation, as in, imagine a number changing from 1 to 2, then 2 to 3, then 3 to 4, etc. over a specified time. Like a counter, except controlled by the same kind of animation that we use for other design animation on the web. This could be useful when designing something like a dashboard,...
Linearly Scale font-size with CSS clamp() Based on the Viewport
25.9.2020
Responsive typography has been tried in the past with a slew of methods such as media queries and CSS calc().
Here, we’re going to explore a different way to linearly scale text between a set of minimum and maximum sizes as the viewport’s width increases, with the intent of making its behavior...
Using max() for an inner-element max-width
7.9.2020
I go into all this in The “Inside” Problem. The gist: you want an edge-to-edge container, but the content inside to have a limited width. I think there is absolutely no problem using a nested element inside, but it’s also fun to look at the possibilities of making that work on...
When Sass and New CSS Features Collide
29.6.2020
Recently, CSS has added a lot of new cool features such as custom properties and new functions. While these things can make our lives a lot easier, they can also end up interacting with preprocessors, like Sass, in funny ways.
So this is going to be a post about the issues I’ve encountered...
Creating Color Themes With Custom Properties, HSL, and a Little calc()
16.4.2020
Before the advent of CSS custom properties (we might call them “variables” in this article as that’s the spirit of them), implementing multiple color schemes on the same website usually meant writing separate stylesheets. Definitely not the most maintainable thing in the world. Nowadays, though,...
A Complete Guide to calc() in CSS
17.3.2020
CSS has a special calc() function for doing basic math. Here's an example:
.main-content {
/* Subtract 80px from 100vh */
height: calc(100vh - 80px);
}
In this guide, let's cover just about everything there is to know about this very useful function.
calc() is for values
The only place you...
Currying in CSS
6.3.2020
Funny timing on this I was just looking at the website for Utopia (which is a responsive type project which I hate to admit I don't fully understand) and I came across some CSS they show off that looked like this:
:root {
--fluid-max-negative: (1 / var(--fluid-max-ratio)...
Logical Operations with CSS Variables
11.9.2019
Very often, while using switch variables (a variable that's either 0 or 1, a concept that's explained in a greater detail in in this post), I wish I could perform logical operations on them. We don't have functions like not(var(--i)) or and(var(--i), var(--k)) in CSS, but we can emulate these...
Weekly news: Truncating muti-line text, calc() in custom property values, Contextual Alternates
26.7.2019
In this week's roundup, WebKit's method for truncating multi-line text gets some love, a note on calculations using custom properties, and a new OpenType feature that prevents typographic logjams.
The post Weekly news: Truncating muti-line text, calc() in custom property values, Contextual...
Responsive Designs and CSS Custom Properties: Defining Variables and Breakpoints
25.2.2019
CSS custom properties (a.k.a. CSS variables) are becoming more and more popular. They finally reached decent browser support and are slowly making their way into various production environments. The popularity of custom properties shouldn’t come as a surprise, because they can be really helpful...
CSS Variables + calc() + rgb() = Enforcing High Contrast Colors
21.2.2019
As you may know, the recent updates and additions to CSS are extremely powerful. From Flexbox to Grid, and — what we’re concerned about here — Custom Properties (aka CSS variables), all of which make robust and dynamic layouts and interfaces easier than ever while opening up many other...
Toggling Animations On and Off
9.1.2019
A nicely detailed tutorial by Kirupa that gets into how you might provide a UI with persisted options that control whether animations run or not.
The trick is custom properties that control the movement:
body {
--toggle: 0;
--playState: "paused";
}
Which are used within animations...
Keep Math in the CSS
12.12.2018
There is a sentiment that leaving math calculations in your CSS is a good idea that I agree with. This is for math that you could calculate at authoring time, but specifically chose not to. For instance, if you needed a 7-column float-based grid (don't ask), it's cleaner and more intuitive:
.col...
DRY State Switching With CSS Variables: Fallbacks and Invalid Values
6.12.2018
This is the second post in a two-part series that looks into the way CSS variables can be used to make the code for complex layouts and interactions less difficult to write and a lot easier to maintain. The first installment walks through various use cases where this technique applies. This post...