09-13-2019, 03:23 PM | #1 |
Addict
Posts: 310
Karma: 2228060
Join Date: Dec 2013
Location: LaVernia, Texas
Device: kindle epub readers on android
|
remove unused CSS rules
I just noticed that when there is an unused class sometimes it will not be removed. Is that because it is in a comma series?
ol, .someunusedclass, ul { font: 0.75em/1.2 "Ubuntu"; background-color: khaki; display: inline-block; width: 100%; } Best regards, Pop |
09-13-2019, 05:21 PM | #2 |
Not Quite Dead
Posts: 195
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
|
Yes, when CSS selectors are "stacked" in the comma separated form, the "remove unused rules" tool does not work. I use a regex to separate out the rules:
--unstack selectors so Calibre "Remove unused rules" tool can be used: Search: ([.]?[^ ]+),\s([^{]+)(\{[^}]+\}) Replace: \1 \3\n\n\2\3 'Replace All' until 0 returns. Clean CSS, then restack or replace class selectors. Apply early in edit session. |
Advert | |
|
09-14-2019, 12:08 AM | #3 |
creator of calibre
Posts: 44,653
Karma: 24966646
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
remove unused classes removes class from class attributes in tags not classes from style rule selectors. Since that rule is used presumbaly because you have ol or ul tags in your book, it wont be removed.
|
09-14-2019, 08:41 AM | #4 | |
Not Quite Dead
Posts: 195
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
|
Quote:
TEST: 1) create stacked selector rules where clearly none are used. The tool removes ALL rules in whatever class/tag form. 2) add a rule into this stack that is clearly used. Run the tool. NONE of the selectors are removed. So if a stack of bad selectors contains one good selector, the ruleset is not cleaned. NO selectors are removed. The selectors have to be unstacked before the tool is applied. Last edited by Brett Merkey; 09-14-2019 at 08:48 AM. |
|
09-14-2019, 10:02 AM | #5 |
creator of calibre
Posts: 44,653
Karma: 24966646
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Its a remove unused CSS tool not a remove unused selectors tool.
|
Advert | |
|
09-16-2019, 09:11 AM | #6 |
Addict
Posts: 310
Karma: 2228060
Join Date: Dec 2013
Location: LaVernia, Texas
Device: kindle epub readers on android
|
separate comma-stacked CSS
Thanks for the info, everyone. I put Brett Merkey's regex into my "saved searches" and tried it out. It works good. As you may notice from the screenshot I am overzealous using comma-separated items. Best regards, Pop
|
09-16-2019, 09:44 AM | #7 |
Resident Curmudgeon
Posts: 76,960
Karma: 138588794
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Personally, I dislike multiple classes put together even if the CSS code is the same. I's cleaner and neater to do it one at a time. That also give the advantage if you need to change one of the classes, you can very easily. And if you sort the classes alphabetically, they will be sorted in the correct order.
I'm not a fan of some CSS shortcuts such as stacking classes and margin:. |
09-16-2019, 09:57 AM | #8 | |
Not Quite Dead
Posts: 195
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
|
@ JSWolf
I agree with you on stacking selectors. But... Quote:
Last edited by Brett Merkey; 09-16-2019 at 10:14 AM. |
|
09-16-2019, 10:14 AM | #9 | |
Grand Sorcerer
Posts: 6,405
Karma: 12408443
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
Quote:
|
|
09-16-2019, 10:35 AM | #10 | |
Resident Curmudgeon
Posts: 76,960
Karma: 138588794
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
Trying to shorthand can come back to bite you. For example, using margin: instead of say margin-left: etc. can bit you if it's on an older nook. Just do it all long form and you'll be better off. |
|
09-16-2019, 11:20 AM | #11 |
Well trained by Cats
Posts: 30,506
Karma: 58055868
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
even with a stacked CSS
a later selector can override the prior declaration. The later one may be for just 1 attribute. Code:
.CO {text-indent: 0} Granted, Wolf's Way, is easier to troubleshoot, but it is not the only way. blockquote p { |
09-17-2019, 06:03 PM | #12 |
Addict
Posts: 310
Karma: 2228060
Join Date: Dec 2013
Location: LaVernia, Texas
Device: kindle epub readers on android
|
I was completely smitten by the brevity of the descendant combinator such as:
<style> .dash {list-style: none;} .dash li:before { content: " — "; margin-left: -2em;} </style> This puts a dash instead of a number or a bullet in front of <li> if surrounded by either <ol> or <ul>. You can even use * to denote any tag enclosed by the class: <style> .whatever * { do:this; do:that; }</style> I'm confused on how combinators, tags, and classes get put into alphabetical order. Best regards, Pop |
09-17-2019, 08:00 PM | #13 | |
Not Quite Dead
Posts: 195
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
|
Quote:
If you are asking what alphabetical order means within a potential zoo of combinators, contextual selectors, pseudo-classes and pseudo-elements, then a lot of head-scratching awaits you when you actually test the tool. Take a very simple contextual selector as an example: it is obvious that rules for blockquote will come before body in a sorted sheet. But where does the contextual selector blockquote p (styling paragraphs within a blockquote) reside in the sort? Hint: nowhere near blockquote. Sorting a sheet may be of use if you are dealing with a huge jumble of CSS and you need to find something — but that something you want to find needs to be real simple and you need to remember to unsort immediately to retain control of the cascade. Last edited by Brett Merkey; 09-17-2019 at 08:24 PM. |
|
09-18-2019, 10:39 AM | #14 |
Addict
Posts: 310
Karma: 2228060
Join Date: Dec 2013
Location: LaVernia, Texas
Device: kindle epub readers on android
|
alphabet sort icon when stylesheet.css is open
When the stylesheet.css is onscreen in the editor you can use the A-Z alphabetizing icon to reorder the stylesheet. I use it all the time with a different philosophy of intent. I prefer the cascade of instructions to (1) begin in the stylesheet (completely independent of order), (2) be overridden by a style command (if present) at the top of each .xhtml segment, (3) finally, be overridden in the text with class="" or style="" in individual tags. For some reason, I have come to think I have made some sort of mistake if the commands in the stylesheet are dependent on their alphabetical place. Still, I am perplexed how the alphabet rules work. Best regards, Pop
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Calibre 3.22: Missing "Remove unused CSS rules" | DrChiper | Editor | 4 | 04-20-2018 04:39 AM |
Inconsistencies in Remove unused CSS rules!? | chaot | Editor | 8 | 04-28-2016 01:38 PM |
Is it possible to reject some changes after using "Remove unused CSS tool"? | bowlins | Editor | 7 | 09-02-2014 05:22 AM |
Remove unused CSS Rules | Divingduck | Editor | 2 | 06-21-2014 08:51 AM |
New "remove unused css" tool | BobC | Editor | 4 | 01-25-2014 10:06 PM |