{"id":20554886,"url":"https://github.com/rnyell/postcss-contains","last_synced_at":"2026-02-11T02:07:35.954Z","repository":{"id":261865157,"uuid":"882467685","full_name":"rnyell/postcss-contains","owner":"rnyell","description":"Style elements based on their existing property or declaration.","archived":false,"fork":false,"pushed_at":"2025-02-11T20:42:13.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-15T02:03:21.207Z","etag":null,"topics":["css","postcss","postcss-plugin"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/postcss-contains","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rnyell.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-02T21:15:40.000Z","updated_at":"2025-02-11T20:42:16.000Z","dependencies_parsed_at":"2024-11-08T22:20:42.383Z","dependency_job_id":"4370f749-a510-4cff-a984-f87849dbfc57","html_url":"https://github.com/rnyell/postcss-contains","commit_stats":null,"previous_names":["rnyell/postcss-contains"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/rnyell/postcss-contains","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rnyell%2Fpostcss-contains","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rnyell%2Fpostcss-contains/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rnyell%2Fpostcss-contains/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rnyell%2Fpostcss-contains/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rnyell","download_url":"https://codeload.github.com/rnyell/postcss-contains/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rnyell%2Fpostcss-contains/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270843582,"owners_count":24655420,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css","postcss","postcss-plugin"],"created_at":"2024-11-16T03:14:09.547Z","updated_at":"2026-02-11T02:07:30.934Z","avatar_url":"https://github.com/rnyell.png","language":"TypeScript","readme":"# postcss-contains\n\n![Build status](https://github.com/rnyell/postcss-contains/actions/workflows/ci.yml/badge.svg)\n\n**postcss-contains** enables you to apply styles to selectors based on specific property or declaration (property-value pair).\n\nThe `@contains` at-rule targets elements and selectors when they _contain_:\n\n- A specific property (e.g. `position` or `margin`)\n- A specific declaration (property-value pair, e.g. `display: grid`)\n\n\n## Installation\n\n```sh\nnpm install postcss-contains --save-dev\n```\n\n\n## Usage\n\n```js\n// postcss.config.js\nimport postcssContains from \"postcss-contains\"\n\nexport default {\n  plugins: [postcssContains],\n}\n```\n\n```css\n@contains (position) {\n  isolation: isolate;\n}\n\n@contains (display: grid) {\n  grid-auto-flow: column;\n}\n\nheader {\n  position: fixed;\n}\n\ndiv {\n  position: relative;\n  display: grid;\n}\n```\n\nOutput:\n\n```css\nheader {\n  position: fixed;\n  isolation: isolate;\n}\n\ndiv {\n  display: grid;\n  grid-auto-flow: column;\n  isolation: isolate;\n}\n```\n\n## Edge Cases\n\n### Conflicts\n\nIf there's a style conflict between a `@contains` and a selector, the selector's styles prevails by default. To modify this, use the `overrides` keyword.\n\n```css\n@contains overrides (display: inline-block) {\n  padding: 1rem;\n  color: red;\n}\n\ndiv {\n  display: inline-block;\n  color: blue;\n}\n```\n\nOutput:\n\n```css\ndiv {\n  display: inline-block;\n  padding: 1rem;\n  color: red; /* the color would remain intact if the `override` was not present */\n}\n```\n\n\n### Duplications\n\nWhen two `@contains` rules target the same property or declaration, their styles will merge by default.\n\nYou can change this behavior by setting `duplication` option to `\"replace\"`; in this case, the order of appearance will determine which style should be applied: the later contains takes precedence over the former.\n\n```css\n/* Both `@contains` target selectors if they declared `display` property */\n@contains (display) {\n  margin: 1rem;\n  gap: 1rem;\n}\n\n@contains (display) {\n  padding: 1rem;\n}\n\ndiv {\n  display: flex;\n}\n```\n\nOutput (with `duplication: \"merge\"` option - default behavior):\n\n```css\ndiv {\n  display: flex;\n  margin: 1rem;\n  gap: 1rem;\n  padding: 1rem;\n}\n```\n\nOutput (with `duplication: \"replace\"`):\n\n```css\ndiv {\n  display: flex;\n  padding: 1rem;\n}\n```\n\n\u003e Note: If one of two (or many) @contains defined with `overrides`, their styles will be merged with `overrides` too.\n\n\u003e Note: The `overrides` only affects the conflicts between @contains and selectors, not between duplicated @contains rules.\n\nSee [options](#options) for more.\n\n\n### Specificity\n\n\"Property-value\" matches have higher specificity and therefore they take precedence over \"property-only\" matches.\n\nIn the example below, `overflow: hidden` is more speccific than `display`, so `span` gets the `green` color; howwever the third contains also has a color declaration, since `display: block` and `overflow: hidden` have equal specificity —both are paird— then based on the order of appearance the color will be `blue`.\n\n```css\n@contains (display) {\n  color: red;\n}\n\n@contains (overflow: hidden) {\n  color: green;\n}\n\n@contains (display: block) {\n  color: blue;\n}\n\nspan {\n  overflow: hidden;\n  display: block;\n}\n```\n\nOutput:\n\n```css\nspan {\n  overflow: hidden;\n  display: block;\n  color: blue;\n}\n```\n\n\n## Options\n\n#### `duplication`\n\ntype: `\"merge\" | \"replace\"`\n\ndefault: `\"merge\"`\n\n#### `duplication: \"merge\"`\n\n```css\n@contains (padding) {\n  margin: 1rem;\n}\n\n@contains (padding) {\n  border: 0;\n}\n\ndiv {\n  padding: 0.5rem 1rem;\n}\n```\n\nOutput:\n\n```css\ndiv {\n  padding: 0.5rem 1rem;\n  margin: 1rem; /* there wouldn't be any margin if duplication was \"replace\" */\n  border: 0;\n}\n```\n\n#### `duplication: \"replace\"`\n\n```css\n@contains overrides (display: grid) {\n  /* this looses the conflict to the below contains despite including `overrides`;\n  as mentioned, `overrides` only comes to play when there is a conflict between @contains and selectors styles, not when two `@contains` are duplicated. */\n  padding: 1rem;\n  color: red;\n}\n\n@contains (display: grid) {\n  margin: 1rem;\n  color: blue;\n}\n\ndiv {\n  display: grid;\n}\n```\n\nOutput:\n\n```css\ndiv {\n  display: grid;\n  margin: 1rem;\n  color: blue;\n}\n```\n\n**Note:** This option only matters when **two @contains of the same type are duplicated**. In the following example, \"b\" and \"c\" are considered as a duplication but \"a\" and \"b\" are not.\n\n```css\n/* a */\n@contains (color) {}\n\n/* b */\n@contains (color: red) {}\n\n/* c */\n@contains (color: red) {}\n```\n\nMore examples are provided [here](./test/exmaples.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frnyell%2Fpostcss-contains","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frnyell%2Fpostcss-contains","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frnyell%2Fpostcss-contains/lists"}