When I was writing a previous post, I wanted to create custom properties in Javascript that I could use in CSS based on the result of running color.jshttps://colorjs.io/ to convert colors and then test if the browser supports a given colorspace. How does it work? This example, as posted in Using color.js as a bridge between color spaceshttps://publishing-project.rivendellweb.net/using-color-js-as-a-bridge-between-color-spaces/, takes a color defined as a new color.js Color object, converts it to an sRGB string as a default. The script then tests if the browser supports different color spaces LCH and Display-P3 using the css.supportshttps://developer.mozilla.org/en-US/docs/Web/API/CSS/supports method. If the color space is...
This article updates Importing JSON and CSS on Javascripthttps://publishing-project.rivendellweb.net/importing-json-and-css-on-javascript/ and corrects come mistakes from the previous post. In Importing JSON and CSS on Javascripthttps://publishing-project.rivendellweb.net/importing-json-and-css-on-javascript/ we discussed the ability to import CSS and JSON directly into Javascript using ESM syntax and import assertionshttps://v8.dev/features/import-assertions. It is now possible to import JSON and CSS into a Javascript module to have some level of control over when they are processed. We import CSS modules like this: js import sheet from './styles.css' assert { type: 'css' }; And then have the option to add them to the document style sheet or to a custom element's...
A while back I wrote a set of Vue 2 components for a WordPress blog. It wasn't a complete project, was missing functionality that I couldn't figure out how to implement and I was afraid it would lock me into a framework although I would rather get locked into Vue than any of the other frameworks I've seen out there. Rather than work with a specific framework, I decided to revisit this as custom elements/web components. according to Custom Elements Everywherehttps://custom-elements-everywhere.com/ most frameworks, at least those that were tested by the site, have pretty good support for custom elements. Even...
CSS layers resolve another problem with CSS specificity and rule order. as I documented in: Looking forward: CSS Layers and the @layer at-rulehttps://publishing-project.rivendellweb.net/looking-forward-css-layers-and-the-layer-at-rule/ CSS Layers or Cascade Layers are a way to group styles together and then apply them in a specific order. All modern browsers now support cascade layers. The idea behind layers is that you create layers as groups so that all the styles in a layer have the same priority and cascade together. There are three ways to create layers: 1. Using the @layer block at-rule, with styles assigned immediately to it: css @layer base { ......
In the past, we've had to write media queries that check for screen/device width as something like this. This query checks if the screen has a minimum width of 768px css @media min-width: 768px { … } and this query checks if the screen is smaller than 768px css @media max-width: 768px { … } You can also combine tests to determine if the value you're testing is within two values. css @media min-width: 800px and max-width: 1024px { … } The new Media Queries spechttps://www.w3.org/TR/mediaqueries-4/mq-range-context explains the new syntax for media queries using ranges. We can write the media...
This feature is only supported behind a flag in Chromium browsers since version 85 and, as far as I know, there is no polyfill. Do not use this feature in production. The prefers-reduced-data media query detects if the user has requested the web content that consumes less internet traffic via the browser or operating system's data-saver option. Until the introduction of the prefers-reduced-data media query, there was no way to honor the data-saver settings. In a music shop app or in any other application where we have a lot of images representing products, we can ask the browser to remove...
Of all the new features the one I've been researching is @custom-media. Custom media queries allow you to create, in essence, create variables in CSS where we associate a name with a media query and can reuse it throughout the stylesheet. This is useful as it gives authors a single place to make changes and prevents errors due to typos and not updating a media query exactly the same way everywhere it is used. Naming things is also important. As Adam Argyle points out in No media query variableshttps://web.dev/state-of-css-2022/no-media-query-variables: > Naming things is very important: it can align purpose with...
The color-contrast CSS function checks the contrast between two colors, usually a background color and black or white text. At its simplest, color-contrast works like this: We first set up a background color with a variable specified in the :root element. We then set the color to be the one that provides the highest contrast with the background color among our choices the color we want to test against and our color choices are separated by the string vs. css .item1 { background-color: var--color1; color: color-contrastvar--color1 vs black, white; } But the colors to use for the text color are...
There are a lot of interesting color features in CSS that are either under development, have recently been implemented in browsers, or are in development in one or more browsers. New color spaces CSS Color Level 4 specification introduces many new color spaces into the CSS world. Some of these, like display-p3, are already supported in Safari while others are just becoming available in Chromium browsers hwb HWBhttps://developer.mozilla.org/en-US/docs/Web/CSS/colorvalue/hwb stands for hue, whiteness, and blackness with an optional fourth value separated by a slash representing alpha transparency. css hwb194 0% 0% / 00c3ff / hwb194 0% 0% / .5 / 00c3ff...
I'm starting to work with interviews. I would like to be able to get the audio transcribed to text and then store the text and the metadata about the interview in a no-SQL/non-relational database that I can then query using either xQuery, NoSQL, or SQL databases. The idea: > Create a tool to automatically transcribe interviews and other audio files into an XML database. Then use XQuery to build the metadata for the interviews. These are preliminary notes and ideas, where possible I will try to incorporate code to validate them but it won't be perfect or possible to do...