As many people are now utilising the Tailwind capabilities of Cwicly, one requirement that we all have is to be able to style blocks that we can’t directly control from our templates (such as blocks within Post Content and third-party blocks).
Fortunately, Cwicly + Tailwind has you covered.
In Tailwind, we are provided with a key way of constructing dynamic classes that can be applied to Cwicly blocks and used to target child selectors, similarly to how relative styles work in Cwicly - these are Arbitrary Variants.
Taking as an example this current way to style post content using relative styles:
To do this with Tailwind, for each “inner” or third party block you want to style, you will need to add an Arbitrary Variant class for each style you want to apply to the Cwicly Post Content Block that contains those blocks.
Here are the steps to target descendant blocks by applying class using an Arbitrary Variant:
- In Tailwind mode, click the + button to open the class dialog
- Type in
[&_tag]
where tag is the tag of the html element you are targeting (e.g.[&_p]
) - Add
:
and the Tailwind class you want to apply to to this html element (e.g.:mb-4
) and press “Create” or select this from the Tailwind class filter list - At this point your class should look like this
[&_p]:mb-4
You can repeat this for as many tags as you want to target and for as many styles as you want to apply.
When you have finished you can wrap the common classes you want to share between Post Content blocks these in a Shell by clicking the “Convert to Shell” button.
You can then add additional shared Post Content styles to this shell later on by clicking on the shell and adding more Arbitrary Variant classes or other classes at any time:
With Cwicly + Tailwind you can do a lot more than this, and this tip just barely scratches the surface of what can be achieved, so it is meant as an intro to help get you started.
Similarly to Cwicly relative styles, Tailwind allows you to target nested blocks with pseudo states and allows you to use other types of selectors, such as direct child and sibling, so the possibilities are endless.
Please also see these feature requests for making this process even easier and more powerful: