RSSAmplifier

Blog

Tobias Ahlin

Home of tobiasahlin.com

tobiasahlin.comRSS feed ↗10 posts

Latest posts

Responsive type scales with composable CSS utilities

If you’ve ever attempted to create responsive type that seamlessly adapts and scales between pre-determined sizes within a type scale based on viewport or container widths, you may have wrestled with JavaScript or wrangled with CSS calculators. But with the help of calc() , clamp() , and a somewhat wonky use of CSS vars , we can simplify this process and tap into the dynamism that modern CSS…

Hiding empty elements with CSS :empty and :has()

You might be used to adding and removing .open and .closed classes on div s and containers to control their state styles. What if we could just write CSS that reflected the state of the DOM, without having to additionally handle state by toggling classes? In this post, we’ll explore how to hide elements with the :empty pseudo-class if they have no children, and how to make the pattern more…

Selecting previous siblings with CSS :has()

One of the more maddening limitations of CSS was for long its inability to select elements based on their children or preceding siblings. This made it impossible to construct CSS selectors that could target previous siblings of an element, but the has:() pseudo-class (along with :not() , :where() , and :is() from Selectors Level 4 ) has thrown out the old limitations and opened up a new world of…

A brief introduction to A/B-testing

A/B-testing is a guiding compass for making product decisions. More technically, it’s a method for quantifying the impact of product variations. The process can’t tell us if one variation is unequivocally “better” than another, but it can tell us which of a set of variations is better at producing a certain effect, encouraging a behavior, or achieving a goal. The basic method is similar to a…

Chaining styles with a JavaScript Proxy

One of the delights of working with Ruby and jQuery is the ability to chain methods, enabling you to conveniently invoke multiple methods on the same target. In jQuery, for example, most methods return a jQuery object, so you can build a chain of methods where every new method operates on the previous target. This enables you to update some styles, run an animation, and update an attribute, all…

Smoother & sharper shadows with layered box-shadows

Default Smooth As light hits an object and a shadow is cast, the shadow can take on a myriad of unique characteristics. If you try to capture the subtleties of a real shadow with box-shadow then, well, you’re pretty much out of luck. The box-shadow CSS property isn’t exactly built to encourage expressiveness. It essentially produces a blurred silhouette of an object—you can change its offset, blur…

Cheat sheet for moving from jQuery to vanilla JavaScript

jQuery is still a useful and pragmatic library, but chances are increasingly that you’re not dependent on using it in your projects to accomplish basic tasks like selecting elements, styling them, animating them, and fetching data—things that jQuery was great at. With broad browser support of ES6 ( over 96% at the time of writing), now is probably a good time to move away from jQuery. I recently…

Breaking to a new row with flexbox

Here’s the challenge: if you want to create a flexbox layout with several rows of items, how do you control which item ends up in which row? Presume you want to create a layout that looks something like this, with three stacked items and alternating full-width items: A common way of controlling the positioning and size of flex items is to use width or flex-basis ; if we set the fourth item to have…

CSS masonry with flexbox, :nth-child(), and order

On the surface it seems fairly easy to create a masonry layout with flexbox ; all you need to do is set flex-flow to column wrap and voilà, you have a masonry layout. Sort of. The problem with this approach is that it produces a grid with a seemingly shuffled and obscure order. Items will be (unbeknownst to the user) rendered from top to bottom and someone parsing the grid from left to right will…

Common CSS Flexbox Layout Patterns with Example Code

In theory, it’s pretty straightforward to use flexbox (Flexible Box Module) to build complex layouts, but I’ve often found myself adding display: flex to an element and then promptly spending an eternity trying to figure out how to make anything behave like I expect it to. If you’re anything like me: here’s a list of 10 example flexbox layouts with CSS that you can copy and paste to get started…