::before and ::after are interesting but, to me, they are hard to understand and use correctly. These pseudo-elements are primarily used to insert content before and after an element. We can create interesting effects, particularly used with the contenthttps://developer.mozilla.org/en-US/docs/Web/CSS/content property from CSS Generated Content Modulehttps://w3c.github.io/csswg-drafts/css-content/ Level 3 specification. In this post, we'll look at some examples of how these pseudo-classes work. Two notes before we begin: The current syntax for these pseudo-elements is ::before and ::after. In CSS 2.1 the syntax was :before and :after with a single colon. Screen readers and other assistive technologies will not read the content...
As a follow-up to the prior post on converting JSON/JSON5 to CSS, we will look at providing font override metrics for fallback fonts and how to use them. Katie Hempenius provides a spreadsheet with the override valueshttps://github.com/khempenius/font-fallbacks-dataset for all fonts in the Google Fonts collection. If the font is not available in Google Fonts or you have the font available, you can use tools like Fontkithttps://www.npmjs.com/package/fontkit to query the font and get metrics for font fallbacks. The metrics that we need are: ascent descent lineGap UnitsPerEm And we use them to calculate the override values as follows: ascent-override = ascent/unitsPerEm...
The more I work with JSON in WordPress theme blocks, the more frustrated I become even though I understand why things are the way they are. JSON has become the default data interchange program for the web. It is not without its issues. Since it's meant mostly for machine-to-machine communication it is unforgiving of parsing and syntax errors. However, even though it is meant for machine communication, JSON is still written by hand by one or more humans. As such, I find the ideas in Suggested improvements to JSONhttp://bolinfest.com/essays/json.html to match my thinking on the subject. They can be summarized...
When doing web development, one of the biggest pains is to have a local server where we can run the code without having to manually reload the page. This post will explore both third-party packages and built-in HTTP servers in multiple languages. Node For a variety of reasons, I've chosen Vitehttps://vitejs.dev/ as my base development environment. You can choose whether to use Typescript or a framework. In this example, we'll create a new workspace using Typescript and no framework. To start a new project with Vite, the command will depend on the version of NPM you're using. If you're using...
data attributes give developers a very powerful tool to create custom code on both CSS and Javascript. This post will look at three things: What are data attributes How to use data attributes in CSS How to use data attributes in javascript What are data attributes datahttps://developer.mozilla.org/en-US/docs/Web/HTML/Globalattributes/data- attributes allow you to insert arbitrary data on your HTML without hacks, and then use it in CSS and Javascript. The names of data attributes have the following restrictions The name must not start with the string xml case-insensitive The name must not contain any colon characters : The name must not contain...
I've been working on learning more about Grids used in book design and publishing and how it may be possible to apply them to web layouts. Grids are not without challenges when working on the web. There are many form factors to consider which means we may have to use media queries to modify the layout But let's start with the types of grids we may want to build or, in other words, what would we build grids for. I've always said that there is no reason why the web can't be like print and newer CSS tools like grid,...
One of the most interesting new CSS features coming into browsers is color-mixhttps://developer.chrome.com/blog/css-color-mix/. We will look at two uses of color-mix: - Mixing colors - Lightening and darkening a color We will also discuss some of the drawbacks of the color-mix function and how it relates to relative colors Mixing Colors It allows you to combine two colors, the percentages that we want to mix them and output the result. The default colorspace is oklabhttps://w3c.github.io/csswg-drafts/css-color-4/ok-lab and we can change the color space when defining the mix. The basic use of color-mix is to actually mix the colors. The structure of...
Dropcaps have been around for a long time both in printed media and the web. On the web it used to be a pain to do it but, hopefully, this is changing with the introduction of the initial-letter property to work alongside the ::first-letter pseudo-element. The initial letter property takes one or two values numbers or percentages. Using one value tells the browser how many lines the drop cap should take. The top of the drop cap letter will be aligned with the top of the first line of text and will drop down as many lines as specified. The...
Design tokens provide a way to create representations of design assets like colors, fonts, spacing, animations, assets, etc., for styling and building cross-platform user interfaces. One of the challenges with cross-platform product development is that operating systems use different style properties and formats to represent the same data. For example, the following code represents the same colors on different platforms: HEX CSS: FCC821 RGB CSS: rgb252, 200, 33 RGBA CSS: rgba252, 200, 33, 1 LCH CSS: lch83.525%, 53.373%, 83.39% Octal Android/Flutter: 77144041 Instead of using these individual properties, designers and engineers reference a token like color.palette.primary representing all four color...
The most frequent uses of border-radius I see are to make images round without modifying the image. css .circle-radius { border-radius: 50%; } or to round the corners of a rectangular box. css .round-corners { border-radius: 20px; } But there is more that you can do with border-radius. The shorthand property can take one to four values that will produce different results. If we provide one value for border-radius then all border radius elements will have the same value. css .example { border-radius: 15px; } / equivalent individual attributes / .example { border-top-left-radius: 15px; border-top-right-radius: 15px; border-bottom-right-radius: 15px; border-bottom-left-radius: 15px...