stylebot icon indicating copy to clipboard operation
stylebot copied to clipboard

[Feature] Remove !important that is auto added

Open sisheng1998 opened this issue 3 years ago • 7 comments

Hi there, this extension is the best for adding CSS code while developing a website.

But the extension will auto add !important to every CSS property that we wrote, this might be a problem because the !important will definitely override the other same selector with the properties that without !important. This might cause us to write a selector not specific enough to override the existing specific selector because of !important.

So when I copy-paste the CSS code to update my website, some of the properties won't show because the existing specific selectors override the new selector that we wrote.

I hope this extension can have an option to let us turn off the auto-add !important to the stylesheet. We can add it ourselves when needed.

Thanks.

sisheng1998 avatar Sep 18 '21 07:09 sisheng1998

maybe a !unimportant, or just a option of some sort?

BobVarioa avatar Oct 14 '21 22:10 BobVarioa

In fact it would be better to have an option in Stylebot to remove !important in a specific stylesheet delivery.

A-In the case I want to permanently modify a layout for my own usage, I would leave the "IMPORTANT" override ON for that site.

B-But it the case I use stylebot to make local tests for something that will go live one day in my developments, I would toggle it OFF. So that my styles apply in the context, as expected. And if really I need !important on a class, I would add it myself to the class.

I believe this "per site toggle" would be an easy fix and would really help developers prepare changes.

8p-design avatar Apr 26 '22 16:04 8p-design

While a toggle per site is definitely a good idea, I personally would like to see the option to turn it off for specific lines. I have some css variables that I wanted to do some calculations over, but calculations don't really work when stylebot will add !important:

calc(var(--number) + var(--number)) calc(100 !important + 100 !important) causes an error

JonasKalkman avatar Jul 22 '22 13:07 JonasKalkman

calc(100 !important + 100 !important) causes an error

Have you made an issue for this specific problem?

pl0xy avatar Oct 02 '22 23:10 pl0xy

I was going to, but it seems to have been fixed already. I can't reproduce it on Chrome anyways.

JonasKalkman avatar Oct 03 '22 09:10 JonasKalkman

According to the source code, !important is not added in the at-rule block.

https://github.com/ankit/stylebot/blob/bc9d8108f4cd4570ce4bf2fe32f189d09adbaf3e/src/css/declaration.ts#L76-L78

Here is an exmaple to use @media all, which is effective always.

@media all {
    pre {
        font-family: "My Fancy Mono", monospace;
    }
}

doitian avatar Aug 05 '23 06:08 doitian