Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Generating fluid CSS typography clamps from static Figma variables

I opened a pull request on Thursday and saw 42 lines of fresh CSS. It was entirely media queries. A developer was trying to make our heading elements scale down gracefully for mobile screens. They had hardcoded a pixel value for desktop. Then they added another block for tablet. Then another block for mobile. Multiply that by six heading levels and it gets out of hand quickly. We needed a better…

A developer submitted a pull request on Thursday, adding 42 lines of media queries to handle responsive typography. The issue was that heading elements were hardcoded to specific pixel values for desktop screens, leading to a tedious process of creating breakpoints for each heading level. The solution lies in using the CSS clamp() function, which allows the browser to calculate font sizes dynamically based on viewport width.

This approach eliminates the need for manual breakpoint creation. To implement this, designers provide static numbers for font sizes at mobile and desktop breakpoints. The developer must then convert these numbers into a format that can be easily manipulated in code. The process involves exporting typography variables from Figma, organizing them in a JSON file with minimum and maximum values, and then using a Node script to generate a CSS file with fluid typography rules.

The script reads the JSON file, determines viewport boundaries, converts pixel values to rem units for scalability, calculates the slope for font size adjustment, and finally outputs a CSS file containing the fluid typography rules.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

Checklist de 15 minutos para montar a operação de lojas e perfis em celulares na nuvem

Aviso rápido: trabalho no time de marketing da DuoPlus. A lista abaixo é a que usamos para colocar uma equipe nova para rodar sem dor de cabeça.

  • Define naming standard for each operation (client - country - platform - function)
  • Assign dedicated cloud phone for each store or client with separate data
  • Standardize Android version across client group for simplified support

How Content Filtering Works in Streaming Apps

Content filtering in streaming apps is a layered pipeline. It decides what shows up for each user based on age ratings, content tags, and viewing history. Not a single block-or-allow decision.

More from Wednesday 25 November →