question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Merging non-adjacent media queries not working

See original GitHub issue

Hi, Im trying to merge non-adjacents media queries.

Is it possible to do it? I also tried on the playground : https://jakubpawlowicz.github.io/clean-css/ But I cant do it, am i missing something? mergeAdjacentRules is set to true…

here is my set-up :

Environment

  • clean-css version - 4.2.1:
  • node.js version - v10.16.3:
  • operating system: win10

Configuration options

var CleanCSS = require("clean-css");
var source = "@import url(design-system.css);";
var output = new CleanCSS({
  level: {
    2: {
      mergeAdjacentRules: true, // controls adjacent rules merging; defaults to true
      mergeIntoShorthands: true, // controls merging properties into shorthands; defaults to true
      mergeMedia: true, // controls `@media` merging; defaults to true
      mergeMediaQueries: true, // controls `@media` merging; defaults to true
      mergeNonAdjacentRules: true, // controls non-adjacent rule merging; defaults to true
      mergeSemantically: false, // controls semantic merging; defaults to false
      overrideProperties: true, // controls property overriding based on understandability; defaults to true
      removeEmpty: true, // controls removing empty rules and nested blocks; defaults to `true`
      reduceNonAdjacentRules: true, // controls non-adjacent rule reducing; defaults to true
      removeDuplicateFontRules: true, // controls duplicate `@font-face` removing; defaults to true
      removeDuplicateMediaBlocks: true, // controls duplicate `@media` removing; defaults to true
      removeDuplicateRules: true, // controls duplicate rules removing; defaults to true
      removeUnusedAtRules: false, // controls unused at rule removing; defaults to false (available since 4.1.0)
      restructureRules: false, // controls rule restructuring; defaults to false
      format: "beautify",
      skipProperties: [] // controls which properties won't be optimized, defaults to `[]` which means all will be optimized (since 4.1.0)
    }
  }
}).minify(source);

Input CSS

h1 {
  font-size: 2.25rem;
  line-height: 1.2222222222;
  margin-bottom: 1rem;
}
@media (min-width: 992px) {
  h1 {
    font-size: 3.75rem;
    line-height: 1.2;
    margin-bottom: 1.5rem;
  }
}

h2 {
  font-size: 2rem;
  line-height: 1.25;
  margin-bottom: 1rem;
}
@media (min-width: 992px) {
  h2 {
    font-size: 3rem;
    line-height: 1.2083333333;
    margin-bottom: 1.5rem;
  }
}

@media (min-width: 992px) {
  ul {
    position: relative;
  }
  li {
    position: relative;
  }
}

Actual output CSS

h1 {
  font-size: 2.25rem;
  line-height: 1.2222222222;
  margin-bottom: 1rem;
}
@media (min-width: 992px) {
  h1 {
    font-size: 3.75rem;
    line-height: 1.2;
    margin-bottom: 1.5rem;
  }
}
h2 {
  font-size: 2rem;
  line-height: 1.25;
  margin-bottom: 1rem;
}
@media (min-width: 992px) {
  h2 {
    font-size: 3rem;
    line-height: 1.2083333333;
    margin-bottom: 1.5rem;
  }
  li,
  ul {
    position: relative;
  }
}

Expected output CSS

h1 {
  font-size: 2.25rem;
  line-height: 1.2222222222;
  margin-bottom: 1rem;
}

h2 {
  font-size: 2rem;
  line-height: 1.25;
  margin-bottom: 1rem;
}

@media (min-width: 992px) {
  h1 {
    font-size: 3.75rem;
    line-height: 1.2;
    margin-bottom: 1.5rem;
  }
  h2 {
    font-size: 3rem;
    line-height: 1.2083333333;
    margin-bottom: 1.5rem;
  }
  ul {
    position: relative;
  }
  li {
    position: relative;
  }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:7

github_iconTop GitHub Comments

1reaction
SukkaWcommented, Sep 3, 2020

This project seems abandoned, anyone have a better alternative?

@stephenbe

cssnano doesn’t support media queries merging at all, so I am using https://github.com/hail2u/node-css-mqpacker with postcss + cssnano now. They produce even smaller css files when working together.

1reaction
stevenbriscoecacommented, Sep 3, 2020

This project seems abandoned, anyone have a better alternative?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Merging non-adjacent media queries not working · Issue #1101
Hi, Im trying to merge non-adjacents media queries. Is it possible to do it? ... Merging non-adjacent media queries not working #1101.
Read more >
Merging media queries, using SASS and Breakpoint ...
Using SASS and Respond-To (Breakpoint) produces a .css file with multiple media queries, not merged. Not a big deal, but in IE8, using...
Read more >
5 Reasons Why Your CSS Media Queries Are NOT Working ...
Why your CSS Media Queries are not working ? CSS Media queries are an important part of Responsive web design but sometimes they...
Read more >
How to Merge Non-Adjacent Partitions in Windows 10, 8, 7?
Need to merge non-adjacent partitions in Windows 10, 8 or, 7? You can use AOMEI Partition Assistant Standard to complete the operation.
Read more >
Maximum sum such that no two elements are adjacent
So to solve the problem, build all the subsequences of the array and find the subsequence with the maximum sum such that no...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found