AMFE Flexible

2.2.1 · abandoned · verified Sun Apr 19

amfe-flexible is a JavaScript library designed to facilitate the creation of flexible web pages on mobile platforms by dynamically adjusting `rem` units based on the viewport width. As of version 2.2.1, it provides a script that modifies the `<html>` element's `font-size` to scale `rem` values, aiming to achieve a consistent layout across various mobile screen sizes. The package appears to be largely unmaintained, with its last significant update several years ago (around 2017), suggesting an abandoned or maintenance-only status. It predates many modern CSS solutions like `vw`/`vh` units, `min()/max()/clamp()` functions, and more sophisticated PostCSS plugins that handle viewport adaptation purely in CSS without JavaScript runtime intervention. Its primary usage involves directly embedding the script in HTML, often alongside `postcss-adaptive` for build-time unit conversion.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to include amfe-flexible directly in an HTML file to enable dynamic rem unit scaling for mobile responsiveness.

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
  <title>AMFE Flexible Demo</title>
  <style>
    body { margin: 0; padding: 0; }
    .container {
      width: 7.5rem; /* Example: 750px in a 100px base font-size design */
      height: 2rem;
      background-color: lightblue;
      margin: 1rem auto;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 0.3rem;
    }
  </style>
  <!-- Include amfe-flexible script after the meta viewport tag -->
  <script src="./node_modules/amfe-flexible/index.js"></script>
</head>
<body>
  <div class="container">
    <p>This text scales with rem units.</p>
  </div>
</body>
</html>

view raw JSON →