Overriding class style

98 views
Skip to first unread message

demon...@gmail.com

unread,
Aug 27, 2020, 8:41:27 AM8/27/20
to TiddlyWiki

I was wondering how to modify a style of a plugin using my own stylesheet. So in this case there is an element in the plugin <span class="graybox"> but this graybox class does not look good in my theme. I am looking for a way to override it in a way that even if I update the plugin at some point (or reset or something) my style will still be in use.

I did notice that if I just make my own .graybox {foo;} style then it will supercede the one give in the stylesheet of the plugin, but Inspect Element -> Style Editor shows that my definitions come later than the ones in the plugin. This would be fine, however, I have no idea why this happens. Is there some sort of order to how the styles are laid out? I tried to remove the $:/tags/Stylesheet tag from my own style tiddler and the plugin's own and add it back to see if that makes a difference in which order the styles are but there was no difference.

So what would be correct way of doing this? I did read about CSS specificity etc but if I understood it correctly then I would have to change the <span class="graybox"> part, which would then be replaced again in the event of my refreshing / updating the plugin.

Mat

unread,
Aug 27, 2020, 11:54:30 AM8/27/20
to TiddlyWiki
Keep the $:/tags/Stylesheet tags. Click one of them to see the global title list of tiddlers using that tag. And, you can rearrange the titles there so to ensure that your stylesheet is placed below the other one. That is how it is evaluated later and "wins", it has the same specificity.

Another way is to increase it's specificity. In this specific case I'd probably go this route and use  !important, i.e like so:

.graybox {foo !important;}

<:-)

Eric Shulman

unread,
Aug 27, 2020, 12:22:44 PM8/27/20
to TiddlyWiki
Yet another way:

Define your style override like this:
.myStyles .graybox { your styles here }

Then, you can add your class ("myStyles") to the PageTemplate by creating a global macro tiddler (tagged with $:/tags/Macro) containing:
\define containerClasses()
tc
-page-container tc-page-view-$(storyviewTitle)$ tc-language-$(languageTitle)$ myStyles
\end
This will override the default "containerClasses" definition found in $:/core/ui/PageTemplate.

Thus, any page content that uses class="graybox" will automatically be within
a wrapper that has a class of "myStyles", and your definition of .graybox will
take precedence due to increased specificity.

-e

PMario

unread,
Aug 27, 2020, 1:57:03 PM8/27/20
to TiddlyWiki
Hi,

The ControlPanel : Info : Advanced : Stylesheet  - menu

allows you to drag & drop sort the stylesheets. ... So the lower in the list, the higher the priority.

-mario


demon...@gmail.com

unread,
Aug 28, 2020, 4:13:35 AM8/28/20
to TiddlyWiki
Ah thank you all, I think the easist for the time being is just to sort the stylesheets in my own order!
Reply all
Reply to author
Forward
0 new messages