Socket
Socket
Sign inDemoInstall

postcss-clamp

Package Overview
Dependencies
5
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    postcss-clamp

PostCSS plugin to transform clamp() to combination of min/max


Version published
Weekly downloads
3.8M
decreased by-0.03%
Maintainers
1
Install size
45.3 kB
Created
Weekly downloads
 

Package description

What is postcss-clamp?

The postcss-clamp package is a PostCSS plugin that allows you to use the CSS 'clamp()' function for responsive typography and layout. It enables you to define a minimum value, preferred value, and a maximum value for font sizes, widths, margins, and other properties, which will be interpolated based on the viewport size.

What are postcss-clamp's main functionalities?

Responsive Typography

This feature allows you to set a scalable font size for headings that adjusts between a minimum of 2rem and a maximum of 3rem based on the viewport width, using 5vw as the preferred size.

h1 { font-size: clamp(2rem, 5vw, 3rem); }

Fluid Spacing

With this feature, you can create fluid spacing that adjusts between a minimum of 1rem and a maximum of 2rem, with 2.5vw as the preferred value based on the viewport width.

p { margin: clamp(1rem, 2.5vw, 2rem); }

Adaptive Widths

This feature enables you to set a container width that adapts between a minimum of 300px and a maximum of 800px, with 50% of the viewport width as the preferred value.

.container { width: clamp(300px, 50%, 800px); }

Other packages similar to postcss-clamp

Changelog

Source

4.1.0

  • Improving clamp replacement (Implemented by https://github.com/Antonio-Laguna)

Readme

Source

PostCSS Clamp

Build Status codecov.io

PostCSS plugin to transform clamp() to combination of min/max.

This plugin transform this css:

.foo {
  width: clamp(10px, 4em, 80px);
}

into this:

.foo {
  width: max(10px, min(4em, 80px));
}

Or with enabled options precalculate:

.foo {
  width: clamp(10em, 4px, 10px);
}

/* becomes */

.foo {
  width: max(10em, 14px);
}

'Can I use' table

Instalation

$ npm install postcss postcss-clamp --save-dev
or
$ yarn add --dev postcss postcss-clamp

Usage

Use PostCSS Clamp as a PostCSS plugin:

const postcss = require('postcss');
const postcssClamp = require('postcss-clamp');

postcss([
  postcssClamp(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);

PostCSS Clamp runs in all Node environments, with special instructions for:

NodePostCSS CLIWebpackCreate React AppGulpGrunt

See PostCSS docs for examples for your environment.

Options

precalculate

The precalculate option determines whether values with the same unit should be precalculated. By default, these are not precalculation.

postcssColorHexAlpha({
  precalculate: true
});

The second and third value has the same unit (px):

.foo {
  width: clamp(10em, 4px, 10px);
}

/* becomes */

.foo {
  width: max(10em, 14px);
}

Here all values have the same unit:

.foo {
  width: clamp(10px, 4px, 10px);
}

/* becomes */

.foo {
  width: 24px;
}

LICENSE

See LICENSE

Keywords

FAQs

Last updated on 11 Mar 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc