-
-
Notifications
You must be signed in to change notification settings - Fork 565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Tailwind CSS integration and styles #88
Comments
The following workaround applies the styles correctly. https://stackblitz.com/edit/github-ypma4c-otrxul?file=astro.config.mjs Disabling import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';
import tailwind from '@astrojs/tailwind';
// https://astro.build/config
export default defineConfig({
integrations: [
starlight({
title: 'My Docs',
customCss: ['./src/styles/base.css'],
}),
tailwind({
config: {
applyBaseStyles: false,
},
}),
],
}); Add the /* src/styles/base.css */
/* @tailwind base; // this breaks starlight styles like theme select, sidebar expandable */
@tailwind components;
@tailwind utilities; Should this be added to the docs? |
Thanks for opening the issue and for sharing that workaround! I’ll have a think what the best approach is. Would be nice not to force the extra How usable do you think Tailwind is without the |
Yes I think it would be good if it works without Tailwind adds preflight styles to the /* src/styles/base.css */
@tailwind base
@tailwind components;
@tailwind utilities; and // tailwind.config.cjs
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'],
corePlugins:{
preflight: false, // disabling preflight styles
},
theme: {
extend: {},
},
plugins: [],
}; |
Ah, yes, only disabling preflight sounds closer to ideal. Starlight does add a minimal reset, although it's not identical to Tailwind's. I think the one that could cause an issue is the default border style they apply — you'd likely need a more verbose syntax to enable borders, e.g. For what it's worth, I believe the fact that customCss is needed here, is an Astro bug. Haven't had time to make a minimal reproduction yet but will do that. Eventually we should add a styling customisation guide to the docs, so once we figure out how to best make this work, we can definitely add a "how to use Tailwind" section to that. |
Yes you are correct, disabling preflight will cause issues with the default boarder styles. I put together a simple TailwindPlay example. When you change the This is how it looks when added to the Starlight content: https://stackblitz.com/edit/github-ypma4c-rg4gmw?file=tailwind.config.cjs I also noticed some additional margin added to the starlight/packages/starlight/components/MarkdownContent.astro Lines 5 to 10 in 8688778
Maybe we could add a class
Yes I think a guide for how to use Tailwind would be a good start. |
Thanks for taking a look. I wonder if it’s practical to improve compatibility and have the Starlight reset be closer to Tailwind’s. Could be tricky to maintain I guess. By the way, looks like you’re building some card links, right? We’re planning to add support for landing pages and some reusable components like that soon just to give you a heads up! Will include cards and some call to action buttons: |
Yes also not quite sure how to handle the compatibility from Starlight reset with Tailwinds. Yes correct, I was planing to build some card links with Tailwind CSS. That sounds and looks awesome! Custom landing page sounds good too. Let me know if I can help with the Tailwind setup documentation or anything else related. |
Note: How to enable dark mode with Tailwind supporting // tailwind.config.cjs
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'],
darkMode: ['class', '[data-theme="dark"]'], // support dark mode 🌑
corePlugins:{
preflight: false, // disabling preflight styles
},
theme: {
extend: {},
},
plugins: [],
}; |
Thanks for sharing! |
Using Tailwind colors to override starlight css variables /* src/styles/base.css */
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
/* Dark Theme */
:root {
--sl-color-white: theme('colors.white');
--sl-color-gray-1: theme('colors.gray.200');
--sl-color-gray-2: theme('colors.gray.300');
--sl-color-gray-3: theme('colors.gray.500');
--sl-color-gray-4: theme('colors.gray.600');
--sl-color-gray-5: theme('colors.gray.700');
--sl-color-gray-6: theme('colors.gray.800');
--sl-color-black: theme('colors.gray.950');
--sl-color-text-accent: theme('colors.teal.200');
}
/* Light Theme */
:root[data-theme='light'] {
--sl-color-white: theme('colors.gray.900');
--sl-color-gray-1: theme('colors.gray.800');
--sl-color-gray-2: theme('colors.gray.700');
--sl-color-gray-3: theme('colors.gray.500');
--sl-color-gray-4: theme('colors.gray.400');
--sl-color-gray-5: theme('colors.gray.300');
--sl-color-gray-6: theme('colors.gray.200');
--sl-color-gray-7: theme('colors.gray.100');
--sl-color-text-accent: theme('colors.teal.700');
}
} |
While not related, I wish there is a way to change the theme itself using Tailwind CSS. |
@marcjulian, did you find a way to accomplish the "not-content" styling so global margin-top styles don't apply to components in Markdown? |
@evan-dunkel I haven't looked into margin-top is also set to 0 for the |
One option is to adopt Tailwind preflight and write the rest of the Starlight CSS on top of it |
Thought I should give a small update in this issue. We’re waiting on withastro/astro#7563 to fix basic Tailwind usage in Starlight routes and also would like to ensure better compatibility for a smoother experience when folks are adding Starlight to sites that have an existing Tailwind config — for example compatibility with Preflight. Still researching what that would take and will want to ensure we’re not negatively impacting people who don’t need Tailwind, but will keep you all posted. In the meantime, Starlight v0.5.0 does include a |
Sounds great. Do you think once this is figured out we should add Tailwind usage to the docs or even create a starwind (starlight + tailwind) example? |
Yes, part of the aim would be a simple recipe in docs of steps to follow to add Tailwind to a Starlight site, including documenting any gotchas that remain, and we could make a template in Hadn’t thought of calling it |
Let me know if I can help you out the the recipe or the |
Thanks so much for the offer @marcjulian! I just pushed up #337 with a draft PR that adds a Tailwind plugin and a starter template — docs still needed. Would be really curious about feedback from you (and everyone else in this thread)! |
What version of
starlight
are you using?0.0.11
What version of
astro
are you using?2.5.5
What package manager are you using?
npm
What operating system are you using?
Mac
What browser are you using?
Chrome, Firefox
Describe the Bug
Adding
@astrojs/tailwind
and using Tailwind CSS utilities in the content should apply the generated CSS.The integration was added using
npx astro add tailwind
and the following tag and utility classes are added tosrc/content/docs/index.md
.The
base.css
is not loaded and thus the styles are not applied, see the Stackblitz demo.Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-ypma4c?file=src%2Fcontent%2Fdocs%2Findex.md
Participation
The text was updated successfully, but these errors were encountered: