How to people manage Tailwind in an RTE stylesheet?
c
I'm a Tailwind newbie and although it's still feels a bit "wrong" I'm persevering with it. One issue I've come across is what to do in an RTE stylesheet. Is there some trick to getting the TW classes to output to the front end while still showing the manual styles in the editor itself? Thanks.
d
Hi craig, my company is using tailwind a lot at the moment and I can share some experiences with you. We keep rte styles separate from tailwind. In our experience, we find it rather inconvenient to combine tailwind with rte. We don't really style our rte much like what it looks in the frontend, we take a more "practical" approach in that we often just add various highlights in the backoffice that approximate a feature, rather than actually adding the feature itself. It gives the editor a vague idea what it will look like in the frontend.
c
But how do you style, say an H2 if you want it to output for example?
I think I might have worked it out. I'll add something like h2 { @apply py-4; // or whatever } To the TailWind css and that will then add a 1rem padding top & bottom to all H2's 🙂 Then in the RTE stylesheet, I'll just pop in an approximation for the editor.
c
Hey craig, We're using tailwind ourselves and this is indeed the route we've ended up taking. We end up utilising postcss nesting to create a standardised class that wraps our rich text editor output on the front end
Copy code
css
.rich-text {
    h1,h2,h3,h4,h5,h6 {
        @apply text-5xl ;
    }
    p,a,li,span {
    }
}
And then we essentially convert that tailwind into 'normal' css for updating the backoffice rendering stylesheet.
Copy code
css
h1 {
   font-size:48px
}

h2 {
}

... etc
Its a little bit of duplication which is annoying, would be nice to be able to inject tailwind into the backoffice stylesheet
c
Actually, just tried this and it works a treat:-
Problem with that approach though is that TW doesn't pick the styles up to include in the output css file. Even if I add
Copy code
content: [
    "./Views/**/*.cshtml",
    "./wwwroot/**/*.{js, css}",
  ],
to the config file and add @apply mx-4 font-semibold to the bottom of the "Styles" section. 😦
e
you could add those to "safelist" https://tailwindcss.com/docs/content-configuration#safelisting-classes or you could create dummy view file with the all the rte classes you might need
c
I confess I've been chatting in the TailWind Discord channel as well. They're tell me to add traditional css properties to the TW input css file and to minimise use of @apply.
Achieves the same results as what you suggested without the extra file. Just adding classes to the TW input file which is already there.
282 Views