Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Update: Yes, LESS Can Help</h2> <p>I hate using <code>!important</code> except in the most extreme circumstances. Most people use it like a chainsaw when they should be using a scalpal to do the job. Nevertheless, I understand the issues facing widget developers like yourself, and your choice to use <a href="https://github.com/premasagar/cleanslate" rel="nofollow noreferrer">https://github.com/premasagar/cleanslate</a> leaves you with no option.</p> <p><a href="https://stackoverflow.com/questions/14201060/add-important-to-all-styles-for-widget-without-javascript/22354353#22354353">Marc's answer</a> noted a good feature of LESS, but he failed to demonstrate how that can help in this matter.</p> <p>If you <strong><em>wrap your entire LESS code</em></strong> in a namespaced mixin, then this feature does exactly what is needed. So assume your widget code looked like this (you mentioned you are already using some type of class for your widget):</p> <pre class="lang-css prettyprint-override"><code>.yourWidgetClass div &gt; p { prop: something; &amp;:hover { prop: some-hover-style; } } .yourWidgetClass .someClass { prop: something; } </code></pre> <p>Then you can do this (wrapping all your widget code in <code>#makeImportant()</code> then calling that mixin with the <code>!important</code> feature noted in Marc's answer):</p> <pre class="lang-css prettyprint-override"><code>#makeImportant() { .yourWidgetClass div &gt; p { prop: something; &amp;:hover { prop: some-hover-style; } } .yourWidgetClass .someClass { prop: something; } } &amp; { #makeImportant() !important; } </code></pre> <p>This produces the following CSS Output:</p> <pre class="lang-css prettyprint-override"><code>.yourWidgetClass div &gt; p { prop: something !important; } .yourWidgetClass div &gt; p:hover { prop: some-hover-style !important; } .yourWidgetClass .someClass { prop: something !important; } </code></pre> <p>For my original (accepted) answer that was way more manually intensive, see the edit history.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload