The WikiText has a quick way to add styles using the @@
syntax. Though this is nice it does become unwieldy with more complex styles like flex and grid, etc.
Another, syntax is the @@.class
syntax but that requires defining your class in a StyleSheet tiddler. And it does get a little persnickety working with block level containers.
And these solutions lack the ability to scope styles to a specific tiddler.
I propose the following which is now wildly available in all modern browsers. Each tiddler is rendered with data-tiddler-title
and data-tags
attributes which means you can select style rules by these attributes.
<style>
[data-tiddler-title="My Tiddler Title"] {
.container {
display: grid;
}
img {
width: 32px;
height: 32px;
}
}
</style>
<div class="container">
{{image1}}
{{image2}}
</div>
You can even use [data-tiddler-title="{{!!title}}"]
. For tags you can use use the ~=
which will find the tag in a list of space separated values: [data-tags~="MyTag"]
.
Why this helps is that it will scope styles to a specific tiddler or tiddler tagged with. It nests rules allowing for more expressive selections of rules while remaining scoped. The style only applies when the tiddler is visible (rendered) and the rules are removed when the tiddler is removed.
CSS is so cool.