Syrinj
BuSo Pro
- Joined
- Mar 31, 2017
- Messages
- 29
- Likes
- 39
- Degree
- 0
I have a bloated stylesheet, and want to consolidate the styles in order of specificity. Assume that the styles are already in the desired top-to-bottom order of specificity. They simply need to be consolidated.
For example, throughout the stylesheet, I have three different definitions of the `body` element displayed in top-to-bottom order below.
#1:
#2:
#3:
I'm looking for a script that doesn't just minify my CSS, but combines the properties while accounting for specificity and turns this mess into a single definition.
Desired outcome:
Maybe I'm using the wrong search query to describe this (searched for 'minify,' 'consolidate,' 'compress,' 'optimize,' etc.) and have not found what I'm looking for. Does anyone have a script or site they can point me to that assists with this?
(I tried CleanCSS, CSS-Optimize, CSSO, and CSS Redundancy Checker but they don't seem to achieve this particular function, and I've tried using this old answer involving grunt on stackoverflow, but can't even get that to work properly. or maybe I'm just a n00b?)
For example, throughout the stylesheet, I have three different definitions of the `body` element displayed in top-to-bottom order below.
#1:
CSS:
body {
margin: 0
}
#2:
CSS:
body {
margin:0;
min-height:100%;
background-color:#fff;
font-family:Arial, sans-serif;
font-size:14px;
line-height:20px;
color:#333
}
#3:
CSS:
body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; // should override #2
color: #000; // should override #2
font-size: 1rem; // should override #2
line-height: 1.5; // should override #2
}
I'm looking for a script that doesn't just minify my CSS, but combines the properties while accounting for specificity and turns this mess into a single definition.
Desired outcome:
CSS:
body {
margin: 0;
min-height:100%;
background-color:#fff;
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
color: #000;
font-size: 1rem;
line-height: 1.5;
}
Maybe I'm using the wrong search query to describe this (searched for 'minify,' 'consolidate,' 'compress,' 'optimize,' etc.) and have not found what I'm looking for. Does anyone have a script or site they can point me to that assists with this?
(I tried CleanCSS, CSS-Optimize, CSSO, and CSS Redundancy Checker but they don't seem to achieve this particular function, and I've tried using this old answer involving grunt on stackoverflow, but can't even get that to work properly. or maybe I'm just a n00b?)