Chris’ Corner: Esoteric Stuff in CSS

Category Image 052

Listen I ain’t trying to scare you, but this CSS stuff can get complicated. It doesn’t have to be. CSS is just selectors with key value pairs in the end. The vast majority of CSS I write is pretty darn straightforward, especially once you have a general system (what files go where? how do we generally name things? how do we do variables?). But fair is fair, CSS can get wildly complex. It doesn’t help the complexity situation that anything new added increases that complexity, because, well, everything in CSS affects everything else. Selectors can get confusing and nesting can exacerbate that. Variables can get changed at any time and it’s not always clear from where. The situation on the page (sizing, events, settings) can effect what’s happening in CSS in increasingly bigger ways (querying containers, querying user preferences). If you want to push the edges of what CSS can do, now is the time.

I often save links of other people’s explorations of these edges of CSS. They are fascinating to me, naturally, as one of the proprietors of a front-end coding tool and ex-owner of CSS-Tricks. But sometimes I struggle to find a way to share them and contextualize them because of the complexity. In fact I think it’s fair to not use techniques based on complexity alone, after all, you write it you maintain it.

But let’s remove the limiter and look at CSS stuff regardless of how complex it might be.


I’ll start with one that has broken my brain for a few years now. @James0x57 calls this technique “Space Toggles” (who credits Ana Tudor for the discovery). Lea Verou calls it The -​-var: ; hack. Just to lock in my own understanding, I called it The CSS Custom Property Toggle Trick.

The idea is that CSS custom properties can be valid and invalid, a valid value even just being " " (a single space). You can concatenate that custom property with others to produce either-valid-or-invalid other custom properties. If it’s valid, you can do one thing, if it’s invalid, you can use the fallback for the custom property to do another thing. So it’s essentially if/then logic for custom properties.

The closest I ever came to simplifying it is this. And I admit it’s not exactly straightforward.

The good news is that CSS just decided that if() would be a thing, so now we wait for browser implementations. It should be quite a bit more straightforward, although the ease-of-use will lead to more exotic usage of it and, I’m afraid to admit, more complex CSS.


Have you ever prepped for needing to do a sorting algorithm in a job interview? Can you explain what a Bubble Sort is? It’s the one where you loop through a list comparing the two things next to each other, and swap them if they need to be swapped. You keep running through the list until you don’t do any more swaps. I think, anyway, I’m not some computer genius over here. GrahamTheDev is though! Their article Bubble Sort…in PURE CSS? is bonkers.

It literally works.

This is the complexity that comes through the ability to compare variables (e.g. we have min() and max() in CSS now) and set new variables based on other variables. Write enough of that with delays and animations and you got yourself a bubble sort. Good luck grokking all that though.

And speaking of the edges of CSS:

warning: on mobile the last few animations might not play and just go blank. On PC your fan may spin up!

This is a limitation of using so many calculations that rely on previous calculations…I am not sure if it runs out of memory or what, but I defo pushed the limits of CSS here!


What’s the value of cos(25deg) in CSS? Tyler Gaw wanted to figure it out exactly.

I know that will return a number between -1 and 1. But what number?

You can’t even set any property to exactly that, because just the number it produces is invalid for most properties.

You can do something like width: calc(1px * cos(25deg)) then check the width value in the devtools computed styles panel and get close, but not exact. Also, width: cos(25deg) is invalid CSS and using a custom prop like --v: cos(25deg) doesn’t really work either because the custom prop value is stored as cos(25deg).

But obviously cos(25deg) produces a number?! Tyler found a way to extract the CSS-generated number in JavaScript. I felt like having a poke at it too, but I didn’t get much further. I did discover that the output is a unitless number, so it’s valid for CSS properties that take unitless numbers, like line-height. So you can set line-height directly with it and then read the computed value. The problem is the computed value isn’t the direct output of the cos() function it’s the final px value so… blech, hard.


There is some CSS trickery that involves @keyframe animations. For example, styles applied during an animation apply extra strongly, so a style applied with a animation that runs for, say, a year is a way to do style overrides. Not recommended, heh. Setting animations to a particular place and pausing them is another weird trick for managing state in CSS.

Those, at least, I feel like I can get my brain around quickly. Animations have some extra power (and complexity) lately via Scroll-Driven Animations. Roman Komarov is the master recently of extremely exotic and complex CSS trickery, and his Scroll-Driven State Transfer is the pièce de résistance.

… an ability to mirror a particular state of some element — for example, hovered or focused — to an element in a different place on the page without a common or unique ancestral element that could have been used to deliver that state

You might think of :has() as the new hotness for being able to access state anywhere in CSS from anywhere else, and you’d be right, but apparently this trick is a bit more adaptable, not requiring us to write more CSS later:

… we could implement this with the :has() selector, but for any new values we’d have to modify the stylesheet afterwards

It looks like the trick involves those Space Toggles too, meaning I think this is one of the most complicated CSS tricks I’ve ever seen. Apart from the super math-y stuff that always blows my mind, that is.


We’ve established that animations can be one of the vehicles for CSS complexity, which is true when using them just to animate, not strong-arm them into some wild state machine.

One way animations can get complicated is combining them. It was just the other day I reminded myself that nesting elements and then animating them both essentially doubles the speed of the inside animation. That’s just shooting a cannon from an airplane though, no fancy tech there. CSS actually allows us to manually combine animations, with tools like animation-composition. It can be confusing though! Bramus wrote up The mysterious case of using CSS animation-composition: accumulate on a scale transform outlining just how weird it can get even in relatively simple situations. Maybe you’ll scratch your head too:

Accumulating a scale(0.5) with scale(2) does not give scale(2.5) but scale(1.5)

After scratching my own head about this long enough, it did sort of start to make sense. Even though blur(2) and blur(3) certainly make blur(5) when accumulated, those are both “blur something more”. In the case of scale, 0.5 makes something smaller. So adding 2.0 + 0.5 isn’t 2.5 because they aren’t both “do something more”, one is “make smaller” and one is “make bigger”, hence the spec having to step in and explain.

Trying to create a lan-to-lan vpn between two differents networks

Category Image 041

Hello

I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls in two different networks.
Can anyone tell me if it's possible and, if so, give me some advice on how to set up this VPN?
Thanks in advance ^^

P.S : i'm french, so my english can be a little bit clumsy.

Minimizing User Decision Fatigue in Web Design

Category Image 076

Offering an array of choices might seem like an excellent way to cater to diverse user preferences, but more often than not, it can cause decision fatigue, negatively impacting the user experience and conversion rates. So, how do we strategically minimize this fatigue through effective web design?

The UX Designer Toolbox

Unlimited Downloads: 500,000+ Wireframe & UX Templates, UI Kits & Design Assets
Starting at only $16.50 per month!


Decision Fatigue in Web Design

Decision fatigue can lead to a decline in the quality of decisions after a continuous decision-making process. In web design, users can experience this fatigue when faced with too many choices, leading to indecisiveness, frustration, and eventual disengagement.

Hick’s Law plays a part in this, suggesting that the time to make a decision increases with the number and complexity of choices. Nonetheless, Hick’s Law is just a fraction of a much broader picture. Balancing user choices and decision fatigue effectively also requires understanding principles like settling for the first reasonable option, avoiding potential losses, and making decisions based on readily available information.

Strategies to Minimize Decision Fatigue

To help users make confident decisions without causing fatigue, several tactics can be implemented.

Streamlined Navigation

Develop a logical, intuitive navigation path to eliminate unnecessary decision-making. For example, clear categorization in a website’s menu helps users find what they need without going through numerous options.

Prioritized Choices

Present the users with essential choices first and omit irrelevant ones. A home page showcasing the most popular products instead of an extensive catalog can prevent choice overload.

Restricted Options

Limit the number of options at each decision point to avoid overwhelming users. For instance, in a subscription selection, offering three plans – basic, premium, and advanced, can be more effective than having numerous slightly differing options.

Design Strategies to Reduce Cognitive Load

Strategic design choices can further alleviate decision fatigue.

Consistent Design

Keeping design elements consistent throughout the website simplifies cognitive processing. For instance, maintaining the same style for all buttons or icons aids user recognition and reduces the cognitive load.

Utilizing Familiar Patterns

Use recognizable icons and layouts to reduce cognitive effort and decision-making time. Employing standard symbols for shopping carts or menus enables users to interact with your website effortlessly.

Anticipatory Design

Predicting user actions and simplifying processes can lessen the number of decisions a user needs to make. Autofilling forms based on past user data is one such example.

Effective Error Handling

Minimize frustration and decision fatigue by guiding users effectively when errors occur. For instance, a clear error message with a suggested solution can keep a user engaged, even in the event of a mistake.

Final Thoughts

Taking into account the principles of decision fatigue and integrating the mentioned design strategies, your web design can become more user-friendly, reducing decision fatigue. Our overview aims to set you on the right path but remember, UX practices often involve deeper explorations and constant testing. Your understanding of decision fatigue will deepen as you engage more with UX research and real-world testing.

While we’re grappling with the complexities of choice, remember there’s another potent tool at your disposal – social proof. Using elements like reviews, testimonials, or popularity indicators can steer users toward decisions others have already made, thus easing their decision-making process. To learn more about how social proof can reinforce user decisions, we invite you to read our article on the topic.

In a world where choice overload is a reality, appreciating the power of simplicity and efficiency in decision-making is invaluable. It’s about striking that optimal balance – giving users ample choice without sparking decision fatigue.

Introduction to MQTT Control Packets

Featured Imgs 26

MQTT control packets are the smallest unit of data transfer in MQTT. MQTT clients and servers exchange control packets for performing their work, such as subscribing to topics and publishing messages.

Currently, MQTT defines 15 types of control packets. If we classify them based on their functionality, we can categorize these packets into three categories: connection, publishing, and subscribing.

Hot-Cold Data Separation: What, Why, and How?

Featured Imgs 26

Apparently, hot-cold data separation is hot now. But first of all:

What Is Hot/Cold Data?

In simple terms, hot data is the frequently accessed data, while cold data is the one you seldom visit but still need. Normally in data analytics, data is "hot" when it is new and gets "colder" and "colder" as time goes by. 

12 Ways To Monetize Your WordPress Blog

Fotolia Subscription Monthly 4685447 Xl Stock
In today’s world, content creation has become a popular medium for self-expression and sharing opinions or expertise. However, many creators devote significant time and effort to their blog posts without earning much in return. Unfortunately, crafting an article requires a considerable amount of time and dedication. Over time, you may have encountered numerous blogs that […]

How to Prevent Changes to Plugins, Themes, and WordPress Core Files

Category Image 091

This is a common question I get from folks in the WordPress community. How can I “lock things down” and prevent any changes to plugins, themes, and WordPress core files. For example, how to prevent any themes and/or plugins from being updated or deleted, and how to prevent any new plugins from being installed. This is useful for certain projects where it’s necessary to lock a website to a static version. Fortunately, WordPress makes this super easy with a couple of PHP constants. Let’s take a quick look..

Contents

Prevent Changes via File Editor

Did you know that WordPress provides a Plugin File Editor and Theme File Editor in the WP Admin Area. You can find them:

  • Under the Appearance menu ▸ Theme File Editor
  • Under the Plugins menu ▸ Plugin File Editor

These tools enable admins to make changes to any plugin or theme files. Huge convenience for those that need it. For those that don’t, you can disable any changes via the file editors by adding the following line to your site’s wp-config.php file, which resides in the root WordPress directory:

// disable file changes via plugin and theme editors
define('DISALLOW_FILE_EDIT', true);

Once this line is included in the site’s configuration file, all file-editing via the Admin Area will be disabled. No menu items, no editing, nada. It’s another layer of security that effectively minimizes your site’s attack surface, so sensitive files cannot be modified by any user, including admins. This helps to protect against any changes that could compromise or crash your site.

Note: As explained at WordPress.org, disabling the file editors via DISALLOW_FILE_EDIT constant may affect any plugins that check for sufficient capabilities using current_user_can('edit_plugins'). Plugins should check if the constant is set, and if so display an appropriate error message.

Prevent All Changes via Admin Area

While the previous technique disables changes to plugins and themes via the file editors, this next technique prevents all changes to any files from inside the Admin Area. This includes:

  • Updating, deleting, installing plugins
  • Updating, deleting, installing themes
  • Updating the WordPress core files

It also includes changes made via the plugin and theme file editors. Basically this technique staticizes a site to its current version. So if that sounds like you, here is the magic code to lock it down:

// disable all changes to all files via admin area
define('DISALLOW_FILE_MODS', true);

Once this line is included in the site’s configuration file, all changes (installing, updating, deleting) to plugins and themes will be disabled. Note that the above line also disables updates to the WordPress core files, so trying to update WordPress via Dashboard ▸ Updates will not work.

Of course, it always is possible for changes to be made directly on the server via SFTP or similar method. But any file changes from within the Admin Area will be disabled completely.

Note: As mentioned, the above line disables all changes from anywhere within the Admin Area, including the file editors. So you do not need to set both DISALLOW_FILE_MODS and DISALLOW_FILE_EDIT. Just including DISALLOW_FILE_MODS takes care of everything.
Note: Be careful when adding DISALLOW_FILE_MODS to your site’s wp-config.php file. WordPress needs to be able to make changes in order to keep plugins, themes, and core files current via updates. So only disable changes if you are 100% certain that you don’t want any updates on your WordPress site.

“What are effective digital marketing strategies for small businesses?”

Featured Imgs 20

Answer:

SEO Optimization:Enhance website visibility with suitable keywords.
Social Media Engagement: Utilize platforms to connect and drive traffic.
Content Marketing: Generate valuable content to attract and inform.
Email Campaigns: Build relationships through personalized emails.
PPC Advertising: Targeted ads for immediate website traffic.
Mobile-Friendly Approach: Perfect for smartphones and analyze data for continuous improvement.

Decoding Duolingo: Returning to the Office, Enabling First-Time Managers, and More

Featured Imgs 26

Remote, hybrid, or in-office? Opinions are divided on what has quickly become one of the most controversial topics in tech: Should we return to the office, and if so, how and when?

On this week’s episode of Dev Interrupted, we sit down with Duolingo’s Sr. Director of Engineering, Fabio Lessa, to discuss how to successfully transition your engineering org back to the office — and why Duolingo has done it so successfully. [Hint: it all starts with culture.]

The npm tea party

Featured Imgs 26

#​700 — August 15, 2024

Read on the Web

👋 Wow, issue 700! We’re back after a week away. Technically I’m still on vacation, but I didn’t want to leave you in the lurch for too long.. 😉
__
Peter Cooper, your editor

JavaScript Weekly

ECMAScript Safe Assignment Operator Proposal — We often feature ECMAScript proposals that are in their later stages, but how about a brand new one you could get involved with? This one proposes an interesting additional bit of language syntax (?=) that returns a [error, value] tuple from an assignment.

Arthur Fiorette

Crafting a 13KB Game: The Story of Space Huggers — We always love Frank’s dives into how he produces neat JavaScript experiments and, in this case, a complete game in just 13KB — and if it inspires you, the latest js13kGames game development competition has just started.

Frank Force

WorkOS: The Modern Identity Platform for B2B SaaS — WorkOS is a modern identity platform for B2B SaaS, offering flexible and easy-to-use APIs to integrate SSO, SCIM, and RBAC in minutes instead of months. It’s trusted by hundreds of high-growth startups such as Perplexity, Vercel, Drata, and Webflow.

WorkOS sponsor

Google’s Angular Lead Sees Convergence in JavaScript Frameworks“When picking a framework, don’t overthink it. It will end up being the same technology anyway with a different facade.” Minko Gechev talks about leading the way in converging Google’s Angular and Wiz frameworks.

Loraine Lawson (The New Stack)

Announcing Official Puppeteer Support for Firefox — As of version 23, Google’s originally Chrome-only Puppeteer browser automation library now has first-class support for Firefox too.

Mozilla Hacks

IN BRIEF:

⭐ If you’ve wondered why so many new npm packages are spam these days, it may be because of ‘Tea’. Though not the drinking kind..

Brendan Eich has expressed his support for the currently stage 1 Decimal draft proposal for bringing a more precise decimal number representation to JavaScript.

There’s an early technical preview of React Native WebGPU. William Candillon shows it off in ▶️ this 9-minute screencast.

RELEASES:

jQuery UI 1.14.0 – The legacy effects and widgets library reduces support for older browsers.

Madge 8.0 – Create graphs of module dependencies.

React Native 0.75, Angular 18.2, Bun 1.1.23, ESLint 9.9

📒 Articles & Tutorials

Patterns for Memory Efficient DOM Manipulation — Marc shares a solid look at the best practices to employ in order to avoid excess memory usage when managing/updating the DOM, all with a hope to make your apps faster. A good overview of the core principles behind DOM manipulation and optimization.

Marc Grabanski

‘How I Won $2,750 using JavaScript, AI, and a Can of WD-40’ — This is far from a technical JavaScript article, but it’s a fun story, involves some code and statistics, and ultimately might make you laugh.

Dave Kiss

Breakpoints and console.log Is the Past, Time Travel Is the Future — 15x faster JavaScript debugging than with breakpoints and console.log, supports Vitest, jest, node:test, and more. Huge changes are coming in Wallaby 2.0! Stay tuned. 🚀

Wallaby Team sponsor

Common Causes of Memory Leaks in JavaScript — Filled with basic examples oriented around V8-based runtimes like Node.js and Deno.

Trevor Indrek Lasn

Learn Web Components — If you’re looking to scrub on your Web Components know-how, this road map should prove useful. It’s a collection of good third party articles covering a wide range of knowledge.

Andrico Karoulla

A Tale of Evading JavaScript Anti-Debugging Techniques — When debugging code written by a third party, there could be some traps thrown in your way to prevent your usual debugging techniques. What to do? Revisiting a popular article from 2023.

Veritas

Fine-Grained Reactivity in Svelte 5 — Taking a close look at Svelte’s new so-called fine-grained reactivity.

Adam Rackis

📄 Tips for Using React Testing Library to Write Unit Tests Pavan Policherla

📄 45 VS Code Shortcuts for Boosting Your Productivity Shahed Nasser

🛠 Code & Tools

Volta 2.0: Install and Run JavaScript Tools Quickly — A long-standing Rust powered tool for installing and switching JavaScript related tools (like Node, TypeScript, Yarn, etc.) … “no matter the package manager, Node runtime, or OS.” GitHub repo.

Volta

Floating UI: Positioning for Tooltips, Popovers, Dropdowns, etc. — A library to create ‘floating’ elements such as tooltips, popovers, and dropdowns. Essentially a next-gen Popper which it now officially succeeds.

atomiks

😘 Kiss Bugs Goodbye — Get 80% automated E2E web and mobile app coverage in under four months with QA Wolf
. With QA cycles complete in minutes (not days), bugs don’t stand a chance. Schedule a demo.

QA Wolf sponsor

React Figma: Use Components as a Source for Figma Designs — A lot of folks use Figma to mock up designs for their React components, but what about the other way around? Use React components as a source for your designs in Figma! GitHub repo.

Ilya Lesik

Ky 1.6 – Simple HTTP client based upon Fetch for browsers, Node & Deno.

True Myth 8.0 – Safe, idiomatic null and error handling in TypeScript with Maybe and Result types.

Protobuf-ES 2.0 – Fully compliant Protobuf implementation for JS/TS.

🕹️ Kontra 10.0 – Lightweight gaming micro-library, optimized for js13kGames.

React Tooltip 5.28 – A tooltip component, surprisingly. (Demo.)

express-validator 7.2 – Express.js middleware for validator.js.

jscodeshift 17.0 – JavaScript codemod toolkit from Facebook.

🌍 Turf.js 7.1 – Modular geospatial analysis engine.

Marked 14.0 – Fast Markdown compiler / parser.