npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

postcss-fluid-length

v0.1.4

Published

PostCSS plugin that creates fluidly interpolated length values

Downloads

674

Readme

postcss-fluid-length

PostCSS plugin that creates fluidly interpolated length values. You can read about the fluid typography in the great articles at Smashing Magazine and CSS Tricks. This approach can be used not only for font sizes, but also for any CSS dimensional properties. But the fluid method requires complex calculations, and this plugin helps to avoid them.

fluid(…) CSS function

This plugin introduces a new fluid() function that allows you to simply enumerate breakpoints and values, like this:

font-size: fluid(16px / 400px, 20px / 800px);

This means: I want to have a font size of 16px for screen widths up to 400px, 20px for widths 800px and wider, and a linear transition in between. So at 600px wide, the font size would be 18px.

This line will be transformed to the:

font-size: 20px;
font-size: clamp(16px, 16px + (100vw - 400px) / 100, 20px);

The first line is a fallback for older browsers, and the second line does all the fluid magic.

You can define more breakpoints, for example:

font-size: fluid(16px / 400px, 20px / 600px, 24px / 1200px);

You can use any static (not v*) length units for breakpoint values/sizes, but all units must be the same for all pairs.

The full syntax of the fluid function is:

fluid( x1 / y1, x2 / y2... [, by 100vw] [, fallback x3] )

The optional parameters are:

  • by 100vw is the dynamic size (in v* units) that should be mapped to the breakpoint sizes. It is 100wv by default.
  • fallback x3 is the fallback value. By default, the maximum of the breakpoint values is used, but it can be overridden in the plugin options.

Plugin usage

Use this plugin in the same way as the other PostCSS plugins:

postcss([require("postcss-fluid-length")(options)]);

The optional options object has the following optional fields:

  • byValue the default by parameter, defaults to "100vw" if not set;
  • fallbackBy the default fallback method, can be "max-value", "min-value" and "none" (omit fallback), defaults to "max-value" if not set;
  • useMinMax use min() and max() functions instead of clamp() (for old Safari), defaults to false if not set.

Limitations

There are some limitations, some of them (marked 🤔) will probably be fixed in the future, and some (🙅) probably not.

  • 🤔 All units must be the same in all breakpoints;
  • 🤔 You can not use CSS variables in breakpoints;
  • 🙅 You can not use calculations inside the function;
  • 🙅 You can not use the fluid() function inside of other calculation, the fluid() call must be solo in the CSS rule.