Snippets
How to Make a Media Query-less responsive Card Component
Here are the CSS ingredients we used for a media-query-less card component:
- The
clamp()
function helps resolve a “preferred” vs. “minimum” vs. “maximum” value.- The
flex-basis
property with a negative value decides when the layout breaks into multiple lines.- The
flex-grow
property is used as a unit value for proportional growth.- The
vw
unit helps with responsive typography.- The
object-fit
property provides finer responsiveness for the card image, as it allows us to alter the dimensions of the image without distorting it.
What is a feed? (a.k.a. RSS)
Use web feeds to subscribe to websites and get the latest content in one place.
Feeds put you in control. It’s like subscribing to a podcast, or following a company on Facebook. You don’t need to pay or hand over your email address. You get the latest content without having to visit lots of sites, and without cluttering up your inbox. Had enough? Easy: unsubscribe from the feed.
You just need a special app called a newsreader.
This site explains how to get started.
Setting Height And Width On Images Is Important Again
tl;dr: browsers now prevent layout shifting when images load using the inline width
and height
values, provided that you use the correct CSS properties when making images responsive.
Layout shifts are very disrupting to the user, especially if you have already started reading the article and suddenly you are thrown off by a jolt of movement, and you have to find your place again. This also puts extra work on the browser to recalculate the page layout as each image arrives across the internet. On a complex page with a lot of images this can place a considerable load on the device at a time when it’s probably got a lot of better things to deal with!
The traditional way to avoid this was to provide
width
andheight
attributes in the<img>
markup so even when the browser has just the HTML, it is still able to allocate the appropriate amount of space[:]
Then the render [should happen] like below, where the appropriate amount of space is set aside for the image when it arrives, and there is no jarring shift of the text as the image is downloaded:
Even ignoring the annoying impact to the user in content jumping around (which you shouldn’t!), the impact on the CPU [of layout shifts] can also be quite substantial.
[…]
So, once we add the dimensions and [
max-width: 100%; height: auto;
], we get the best of both worlds, right? No layout shifts, but also the ability to resize images using CSS? Well until very recently you might have been surprised to find out the answer was in fact: no (I was — hence why I decided to write this article).[…]
This affects any page where we constrain the image size in a responsive manner — i.e. small screen mobile devices. These are likely to be the very users suffering with network constraints and limited processing power that will suffer most from layout shifts! Of course, we ideally should be delivering appropriately sized images for the screen size, but you cannot cover every device size, so often images will need some resizing by the browser, particularly on mobile.
[…]
[I]f the following four conditions are true, then the correct image dimensions could be calculated without needing to wait for the images to download, and so without the need of a content layout shift:
height
is set on the element in HTMLwidth
is set on the element in HTMLheight
(orwidth
) is set in the CSS — including using percentage values likemax-width: 100%;
width
(orheight
) is set toauto
in the CSS.If any one of these were not set, then the calculation would not be possible, and so would fail and be ignored and have to wait for the image to be downloaded.
[…]
So instead [of waiting for a new CSS property], [browsers] could implement the equivalent logic deep in rendering code rather than exposing it via the user-agent stylesheet, but the effect is the same.
[…]
Firefox went ahead and did this as an experiment and then turned it on by default for Firefox 71. Once that was released, then your site may well have just got faster for free — thanks Mozilla!
[…]
After Firefox’s successful experimentation, Chrome also decided to implement this (again using the layout coded method for now rather than default user-agent stylesheet), and rolled it out by default in Chrome 79. This also took care of the other chromium-based browsers (Edge, Opera and Brave, for example). More recently, in January 2020, Apple added it to their Tech Preview edition of Safari, meaning it should hopefully be coming to the production version of Safari soon, and with that, the last of the major browsers will have implemented this and the web will become better and less jolty for a huge number of sites.
Cassie Evans' blog animations
There are so many wonderful animations on Cassie Evans’ website that I love, from the way the site title is drawn in to all the effects when you hover/interact with certain things.
Keeping Browserslist (and Autoprefixer) up to date
You need to run `
npx [email protected] --update-db
` every month to keep browsers data up to date.Otherwise, `
last 2 browsers
` or `> 1%
` will return outdated browsers, Autoprefixer and Babel will add unnecessary polyfills.
Trix: A rich text editor for everyday writing
Trix is an open-source project from Basecamp, the creators of Ruby on Rails. Millions of people trust their text to Basecamp, and we built Trix to give them the best possible editing experience.
[…]
Different By Design
Most WYSIWYG editors are wrappers around HTML’s contenteditable and execCommand APIs, designed by Microsoft to support live editing of web pages in Internet Explorer 5.5, and eventually reverse-engineered and copied by other browsers.
Because these APIs were never fully specified or documented, and because WYSIWYG HTML editors are enormous in scope, each browser’s implementation has its own set of bugs and quirks, and JavaScript developers are left to resolve the inconsistencies.
[…]
Trix sidesteps these inconsistencies by treating contenteditable as an I/O device: when input makes its way to the editor, Trix converts that input into an editing operation on its internal document model, then re-renders that document back into the editor. This gives Trix complete control over what happens after every keystroke, and avoids the need to use execCommand at all.