# container-query-js

> CSS container query polyfill for js | plus additional super powers

Latest version **1.0.2** (published 2021-08-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install container-query-js
pnpm add container-query-js
yarn add container-query-js
bun add container-query-js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2021-08-02 |
| First published | 2021-08-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 371.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | 0shuvo0 |
| Maintainers | 0shuvo0 |
| Keywords | js, css, container, query, polyfill, container-query, container-query-js, ResizeObserver |

## Links

- npm: https://www.npmjs.com/package/container-query-js
- Repository: https://github.com/0shuvo0/container-query
- Homepage: https://github.com/0shuvo0/container-query#readme
- Issues: https://github.com/0shuvo0/container-query/issues
- npm.io page: https://npm.io/package/container-query-js

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.2 (latest) — 2021-08-02
- 1.0.1 — 2021-08-01
- 1.0.0 — 2021-08-01

## README

# container-query
### CSS container query polyfill for js
### but with additional superpowers
It uses ResizeObserver to monitor changes

![demo](preview.gif)

## Installation
```npm i container-query-js```

## Example
```js
import containerQuery from "container-query-js"

containerQuery({
    600: { //when width of elemets is between 0 - 600 these styles will be applies
        ".card": {
            flexDirection: "row",
            textAlign: "left",
            rangeIn: el => !el.classList.contains("mid-size") && el.classList.add("mid-size"), // Will be called when element width is in the range
            rangeOut: el => el.classList.remove("mid-size") // Will be called when element width is out of range
        }
    },
    350: { //when width of elemets is between 0 - 350 these styles will be applies
        ".card": {
            flexDirection: "column",
            ".content": { //You can style childs based on parents width
                paddingTop: "1em",
                paddingLeft: 0,
                margin: "1.5em 0",
                width: (h, w) => parseInt(w / 2) + "px" // You can also use functions, it will receive height and width of current element
            }
        },
    }
})
```

---
_Source: https://npm.io/package/container-query-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
