svelteness / kit-docs

Documentation integration for SvelteKit.
https://kitdocs.vercel.app
MIT License
457 stars 32 forks source link

Namespace CSS #76

Closed davej closed 1 year ago

davej commented 1 year ago

I'm running into issues where kit-docs tailwind styles are taking precedence over my tailwind styles. This is causing my rules for different sized viewports to be ignored. Would it be possible to namespace the CSS so that the styles don't leak, as described here: https://github.com/sveltejs/kit/issues/6706

https://user-images.githubusercontent.com/26971/217309449-913bb34c-46f7-4a6d-b045-3e54b0748c81.mp4

mihar-22 commented 1 year ago

I think the simpler option is to simply make sure that any custom theme config we apply is namespaced:

https://github.com/svelteness/kit-docs/blob/main/packages/kit-docs/tailwind.config.cjs#L11-L39

So fonts being kd-sans, screens being kd-420, and colors being kd-brand, kd-border, etc.

mihar-22 commented 1 year ago

I don't think we need to prefix everything because there's just no need and you'll end up loading all utility styles twice.

davej commented 1 year ago

@mihar-22, I don't think that will work. KitDocs CSS is loaded after my CSS so it takes precedence over my CSS and you have not included the .sm:xxx modifier. The net result is that the classes from kit-docs are taking precedence over my CSS and my .sm: modifier is getting overridden by later rules in KitDocs

Here is how the CSS styles are applied to the same element before and after visiting the KitDocs pages:

Before After
CleanShot 2023-02-08 at 2 51 13@2x CleanShot 2023-02-08 at 2 51 38@2x

It would be ideal if Svelte provided some way of removing the KitDocs CSS when not on a KitDocs route but that does not seem possible (or I'm not sure how).

What do you think? What's the best way forward?

mihar-22 commented 1 year ago

I think I'm missing something. What element are you trying to style in which KitDocs is eventually overriding?

mihar-22 commented 1 year ago

Oh...... wait you're loading the KitDocs Tailwind CSS file. You need to follow the Tailwind integration docs. They're not great docs but the idea is you should copy over the config if you're also using Tailwind.

davej commented 1 year ago

Ok, now I've got it. THANK YOU!

It would be handy if the source theme.css file was available in the packaged version of KitDocs then I could do @import it (without all the Tailwind utility classes) rather than copy-pasting it.