Dublin Library

The Publishing project

Testing front-end code

While building the new blog, I started thinking about testing front-end code again. In this post I will revisit Playwrighthttps://playwright.dev/ Test class, and look at the types of testing that we can do to ensure that the site works as intended. Why test front-end code? I get caught in a deceptively simple question: Why do we need to test the front-end? Because testing will help you catch errors that you don't see. I've had multiple instances where I thought I typed one thing and I had typed something completely different. Testing can also help you identify potential performance bottlenecks before...

Continue reading →

Revisiting the display property

The display property has been around for a long time but its definition has evolved over the years. > Formally, the display property sets an element's inner and outer display types. The outer type sets an element's participation in flow layouthttps://developer.mozilla.org/en-US/docs/Web/CSS/CSSflowlayout; the inner type sets the layout of children. > > Source: MDNhttps://developer.mozilla.org/en-US/docs/Web/CSS/display CSS 2 made a lot of implicit assumptions when dealing with the display property. We can keep using them or we can adopt the more explicit behavior from the CSS Display Module Level 3https://drafts.csswg.org/css-display/ draft specification where you can use values for both inside and outside display...

Continue reading →

Animating Variable Fonts (2023)

One thing I particularly like about variable fonts is that it allows some interesting animation tricks. For example, since variable fonts have information about all possible variations of the font, we can animate discreete values, like weight or italics. There are two things we can do with font animations. We can use native CSS to animate changes to the full word or phrase that we want to animate We can use a library like Splittinghttps://splitting.js.org/ to break the content into letters or words and then animate each unit of content individually Animating blocks of text The easiest thing to do...

Continue reading →

Coloring Text With Gradients

In addition to black and white or single, solid-color text, we can also use gradients to color the text. The process is slightly more complicated than just assigning color to the desired element. 1. Check if the browser supports background-clip and color conversion syntax for linear-gradient 2. Set the color of the text to transparent so that it won't conflict with the background gradient 3. Set the gradient as the background 4. Set the background-cliphttps://developer.mozilla.org/en-US/docs/Web/CSS/background-clip property to text {.custom-ordered} css @supports background-clip: text and background: linear-gradientin oklch to right, A37, 595 { / 1 / .gradient-text { color: transparent; /...

Continue reading →

Creating Sane CSS defaults

Both Eric Meyer's Resethttps://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/ and Normalize.csshttps://necolas.github.io/normalize.css/ are comprehensive solutions to provide a baseline for CSS development. Can I build a set of defaults that make sense for my projects on top of these resets? what shape would this set of defaults take? Ever since I decided to move this blog to Eleventy, I've been thinking about moving the CSS to use @CSS Layershttps://developer.mozilla.org/en-US/docs/Web/CSS/@layer. This would make it easier to organize the stylesheet. Getting started We'll use Normalize as our base layer and leverage the fact that you can import stylesheets directly to a layer Links and resources Introducing the CSS...

Continue reading →

JS conditional (ternary) operator

Javascript provides a way to shortcircuit if/else statements with the conditional or ternary operatorhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditionaloperator. the idea is that we consolidate the three parts of the if statement in one command, like shown below: js function canPassisAdult { return isAdult ? 'Yes, can pass' : 'No, cannot pass'; } In this example, isAdult is the test we want to execute. The string after the question make ? returns if the test is true and the secod string after the colon : returns if the test is false. if the true and false statemnts are too complex or too long, we should...

Continue reading →

An Interesting Image CSS Reset

I came accross reset from Harry Roberts from Twitter/Xhttps://twitter.com/csswizardry/status/1717841334462005661 via Kevin Powell's YouTube videohttps://www.youtube.com/watch?v=345V2MU3Ew. I've adapted the reset by eliminating the low quality image resource. I don't need the low quality images at least I don't think I do. The initial image styles look like this: css img { max-width: 100%; / 1 / height: auto; / 1 / vertical-align: middle; / 2 / font-style: italic; / 3 / font-size: .75rem; / 4 / } Each line performs a specific task: 1. Allow for fluid image sizing while maintaining the image aspect ratio 2. Remove ‘phantom’ whitespace. Softer way to...

Continue reading →

For when you know you will print

There are times when we know that users will print a page of web content. Maybe a set of directions for a recipe, a map with directions or a page of information that we want to preserve. While it's impossible to guarantee how browsers will print the document we can use the print-color-adjusthttps://developer.mozilla.org/en-US/docs/Web/CSS/print-color-adjust property to help the browser in the process. print-color-adjust provides a hint to the user-agent about how it should treat color and style choices that might be expensive or generally unwise on a printer or similar device. If user agents allow users to control this aspect of...

Continue reading →

Defining multiple syntax in CSS variables

In Revisiting Custom Propertieshttps://publishing-project.rivendellweb.net/revisiting-css-custom-properties/ we looked at how to define custom properties using the @property at-rule. One aspect of @property that we didn't discuss are the syntax multipliers and combinators. These two gives us more flexibility when it comes to defining what our @property-defined variables can do. Quick Review A CSS variable defined with @property looks like this: css @property --border-block { syntax: ""; inherits: false; initial-value: 2rem; } The name of the property follows the @property at rule and must have two dashes -- The following list, taken from the Supported Nameshttps://drafts.css-houdini.org/css-properties-values-api/supported-names section of the CSS Properties and Values...

Continue reading →

Revisiting Critical CSS

Crtical CSS is simple in theory but not so much in execution. In this post we'll look at what critical CSS is, how does it work and whether it's still necessary for all use cases. What is Critical CSS Critical CSS is the CSS and assets necessary to render the above the fold content for a given page. You inline this bit of CSS inside a style tag in the head of the document and load the document like you normally would. How does it work? Critical CSS works in three stages 1. Identify the CSS that goes above the...

Continue reading →