tailwindlabs / tailwindcss-typography

Beautiful typographic defaults for HTML you don't control.
https://tailwindcss-typography.vercel.app/
MIT License
4.66k stars 269 forks source link

Changing the default colors #102

Closed justingolden21 closed 2 years ago

justingolden21 commented 3 years ago

Hi,

I'm hoping this isn't a duplicate of https://github.com/tailwindlabs/tailwindcss-typography/issues/26

I've been trying to override the default colors of tailwind typography for hours now and I'm slowly going insane. I tried !important and targeting every class of prose on every screen size and everything and it's still showing the default colors...

I decided to eventually try using dark mode, which has a lot of very unhelpful tutorials and the actual docs which are awesome: https://tailwindcss.com/docs/dark-mode although the problem is this still doesn't work. Adding the dark class to html works for the background color, but the individual prose classes and similar (and there are dozens if not hundreds of them) still have their default colors, and I can only change them by using !important and listing every single one of them, and can only do it programmatically by using javascript...

I'm about ready to give up on this and just remove the typography plugin entirely and set the background-color to black and the color to white... but there's got to be an easier way, right? Is there any way to use the typography plugin without using the colors, or any way to override the default colors? I've seen this article: https://stefanzweifel.io/posts/2020/07/20/add-dark-mode-support-to-at-tailwindcsstypography/ which has this code in the taildwind config:

module.exports = {
    theme: {
        typography: (theme) => ({
            default: {
                css: {
                    color: theme('colors.gray.900'),
                    a: {
                        color: theme('colors.blue.700'),
                        '&:hover': {
                            color: theme('colors.blue.700'),
                        },
                    },
                },
            },

            dark: {
                css: {
                    color: theme('colors.gray.300'),
                    a: {
                        color: theme('colors.green.500'),
                        '&:hover': {
                            color: theme('colors.green.500'),
                        },
                    },

                    h1: {
                        color: theme('colors.gray.300'),
                    },
                    h2: {
                        color: theme('colors.gray.300'),
                    },
                    h3: {
                        color: theme('colors.gray.300'),
                    },
                    h4: {
                        color: theme('colors.gray.300'),
                    },
                    h5: {
                        color: theme('colors.gray.300'),
                    },
                    h6: {
                        color: theme('colors.gray.300'),
                    },

                    strong: {
                        color: theme('colors.gray.300'),
                    },

                    code: {
                        color: theme('colors.gray.300'),
                    },

                    figcaption: {
                        color: theme('colors.gray.500'),
                    },
                },
            },
        }),
    },
};

however it still doesn't work and messes all of my css up (with no errors anywhere). Removing that code again and adding darkMode: 'class', it works as I said before, except the colors are still messed up.

Full (relevant) files

(I'm using jekyll and tailwind, using someone else's (awesome) boilerplate)

tailwind.config.js

module.exports = {
    purge: [
        '{,!(node_modules|_site)/**/}*.{html,md}',
    ],
    theme: {},
    plugins: [
        require('@tailwindcss/typography'),
    ],
    darkMode: 'class',
}

default.html

<!DOCTYPE html>
<html class="dark" lang="{{ site.lang | default: "en-US" }}">

<head>
    {% include head.html %}
</head>

<body class="antialiased bg-gray-100 text-gray-900 dark:bg-gray-800 dark:text-gray-100 min-h-screen">
<!-- <body class="antialiased min-h-screen"> -->
    {{ content }}
    {% include scripts.html %}
</body>

</html>

post.html

---
layout: default
---

<header>
    {% if page.backLink or page.backLink == nil %}
    <a href="/" class="flex items-center m-5 text-xl hover:underline">
        <svg class="w-6 h-6" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
            <path fill-rule="evenodd"
                d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z"
                clip-rule="evenodd"></path>
        </svg>
        <span>Back</span>
    </a>
    {% endif %}
</header>

<article class="prose prose-sm sm:prose lg:prose-lg xl:prose-xl mx-auto dark:prose-dark">
    {{ content }}
</article>

Thanks in advance for any help on this...

justingolden21 commented 3 years ago

Screenshot of what I mean:

image

Even though in dark mode (which I'm in and is working for the background-color) it should be: dark:text-gray-100 as in the body tag: <body class="antialiased bg-gray-100 text-gray-900 dark:bg-gray-800 dark:text-gray-100 min-h-screen">

Removing the dark class from html:

image

So the dark class is working, but it doesn't work for styling the type...

TL;DR: If anyone knows an easy way of just overriding all of the colors for different elements and classes, and then styling them myself, that's all I need...

justingolden21 commented 3 years ago

Here's what I mean by having to override every single default style from this typography plugin:

some generated css for typography colors (warning: a LOT of code) ```css .sm\:prose { color: #374151; max-width: 65ch; } .sm\:prose [class~="lead"] { color: #4b5563; font-size: 1.25em; line-height: 1.6; margin-top: 1.2em; margin-bottom: 1.2em; } .sm\:prose a { color: #111827; text-decoration: underline; font-weight: 500; } .sm\:prose strong { color: #111827; font-weight: 600; } .sm\:prose ol { counter-reset: list-counter; margin-top: 1.25em; margin-bottom: 1.25em; } .sm\:prose ol > li { position: relative; counter-increment: list-counter; padding-left: 1.75em; } .sm\:prose ol > li::before { content: counter(list-counter) "."; position: absolute; font-weight: 400; color: #6b7280; left: 0; } .sm\:prose ul > li { position: relative; padding-left: 1.75em; } .sm\:prose ul > li::before { content: ""; position: absolute; background-color: #d1d5db; border-radius: 50%; width: 0.375em; height: 0.375em; top: calc(0.875em - 0.1875em); left: 0.25em; } .sm\:prose hr { border-color: #e5e7eb; border-top-width: 1px; margin-top: 3em; margin-bottom: 3em; } .sm\:prose blockquote { font-weight: 500; font-style: italic; color: #111827; border-left-width: 0.25rem; border-left-color: #e5e7eb; quotes: "\201C""\201D""\2018""\2019"; margin-top: 1.6em; margin-bottom: 1.6em; padding-left: 1em; } .sm\:prose blockquote p:first-of-type::before { content: open-quote; } .sm\:prose blockquote p:last-of-type::after { content: close-quote; } .sm\:prose h1 { color: #111827; font-weight: 800; font-size: 2.25em; margin-top: 0; margin-bottom: 0.8888889em; line-height: 1.1111111; } .sm\:prose h2 { color: #111827; font-weight: 700; font-size: 1.5em; margin-top: 2em; margin-bottom: 1em; line-height: 1.3333333; } .sm\:prose h3 { color: #111827; font-weight: 600; font-size: 1.25em; margin-top: 1.6em; margin-bottom: 0.6em; line-height: 1.6; } .sm\:prose h4 { color: #111827; font-weight: 600; margin-top: 1.5em; margin-bottom: 0.5em; line-height: 1.5; } .sm\:prose figure figcaption { color: #6b7280; font-size: 0.875em; line-height: 1.4285714; margin-top: 0.8571429em; } .sm\:prose code { color: #111827; font-weight: 600; font-size: 0.875em; } .sm\:prose code::before { content: "`"; } .sm\:prose code::after { content: "`"; } .sm\:prose a code { color: #111827; } .sm\:prose pre { color: #e5e7eb; background-color: #1f2937; overflow-x: auto; font-size: 0.875em; line-height: 1.7142857; margin-top: 1.7142857em; margin-bottom: 1.7142857em; border-radius: 0.375rem; padding-top: 0.8571429em; padding-right: 1.1428571em; padding-bottom: 0.8571429em; padding-left: 1.1428571em; } .sm\:prose pre code { background-color: transparent; border-width: 0; border-radius: 0; padding: 0; font-weight: 400; color: inherit; font-size: inherit; font-family: inherit; line-height: inherit; } .sm\:prose pre code::before { content: ""; } .sm\:prose pre code::after { content: ""; } .sm\:prose table { width: 100%; table-layout: auto; text-align: left; margin-top: 2em; margin-bottom: 2em; font-size: 0.875em; line-height: 1.7142857; } .sm\:prose thead { color: #111827; font-weight: 600; border-bottom-width: 1px; border-bottom-color: #d1d5db; } .sm\:prose thead th { vertical-align: bottom; padding-right: 0.5714286em; padding-bottom: 0.5714286em; padding-left: 0.5714286em; } .sm\:prose tbody tr { border-bottom-width: 1px; border-bottom-color: #e5e7eb; } .sm\:prose tbody tr:last-child { border-bottom-width: 0; } .sm\:prose tbody td { vertical-align: top; padding-top: 0.5714286em; padding-right: 0.5714286em; padding-bottom: 0.5714286em; padding-left: 0.5714286em; } .sm\:prose { font-size: 1rem; line-height: 1.75; } .sm\:prose p { margin-top: 1.25em; margin-bottom: 1.25em; } .sm\:prose img { margin-top: 2em; margin-bottom: 2em; } .sm\:prose video { margin-top: 2em; margin-bottom: 2em; } .sm\:prose figure { margin-top: 2em; margin-bottom: 2em; } .sm\:prose figure > * { margin-top: 0; margin-bottom: 0; } .sm\:prose h2 code { font-size: 0.875em; } .sm\:prose h3 code { font-size: 0.9em; } .sm\:prose ul { margin-top: 1.25em; margin-bottom: 1.25em; } .sm\:prose li { margin-top: 0.5em; margin-bottom: 0.5em; } .sm\:prose > ul > li p { margin-top: 0.75em; margin-bottom: 0.75em; } .sm\:prose > ul > li > *:first-child { margin-top: 1.25em; } .sm\:prose > ul > li > *:last-child { margin-bottom: 1.25em; } .sm\:prose > ol > li > *:first-child { margin-top: 1.25em; } .sm\:prose > ol > li > *:last-child { margin-bottom: 1.25em; } .sm\:prose ul ul, .sm\:prose ul ol, .sm\:prose ol ul, .sm\:prose ol ol { margin-top: 0.75em; margin-bottom: 0.75em; } .sm\:prose hr + * { margin-top: 0; } .sm\:prose h2 + * { margin-top: 0; } .sm\:prose h3 + * { margin-top: 0; } .sm\:prose h4 + * { margin-top: 0; } .sm\:prose thead th:first-child { padding-left: 0; } .sm\:prose thead th:last-child { padding-right: 0; } .sm\:prose tbody td:first-child { padding-left: 0; } .sm\:prose tbody td:last-child { padding-right: 0; } .sm\:prose > :first-child { margin-top: 0; } .sm\:prose > :last-child { margin-bottom: 0; } .sm\:prose-sm { font-size: 0.875rem; line-height: 1.7142857; } .sm\:prose-sm p { margin-top: 1.1428571em; margin-bottom: 1.1428571em; } .sm\:prose-sm [class~="lead"] { font-size: 1.2857143em; line-height: 1.5555556; margin-top: 0.8888889em; margin-bottom: 0.8888889em; } .sm\:prose-sm blockquote { margin-top: 1.3333333em; margin-bottom: 1.3333333em; padding-left: 1.1111111em; } .sm\:prose-sm h1 { font-size: 2.1428571em; margin-top: 0; margin-bottom: 0.8em; line-height: 1.2; } .sm\:prose-sm h2 { font-size: 1.4285714em; margin-top: 1.6em; margin-bottom: 0.8em; line-height: 1.4; } .sm\:prose-sm h3 { font-size: 1.2857143em; margin-top: 1.5555556em; margin-bottom: 0.4444444em; line-height: 1.5555556; } .sm\:prose-sm h4 { margin-top: 1.4285714em; margin-bottom: 0.5714286em; line-height: 1.4285714; } .sm\:prose-sm img { margin-top: 1.7142857em; margin-bottom: 1.7142857em; } .sm\:prose-sm video { margin-top: 1.7142857em; margin-bottom: 1.7142857em; } .sm\:prose-sm figure { margin-top: 1.7142857em; margin-bottom: 1.7142857em; } .sm\:prose-sm figure > * { margin-top: 0; margin-bottom: 0; } .sm\:prose-sm figure figcaption { font-size: 0.8571429em; line-height: 1.3333333; margin-top: 0.6666667em; } .sm\:prose-sm code { font-size: 0.8571429em; } .sm\:prose-sm h2 code { font-size: 0.9em; } .sm\:prose-sm h3 code { font-size: 0.8888889em; } .sm\:prose-sm pre { font-size: 0.8571429em; line-height: 1.6666667; margin-top: 1.6666667em; margin-bottom: 1.6666667em; border-radius: 0.25rem; padding-top: 0.6666667em; padding-right: 1em; padding-bottom: 0.6666667em; padding-left: 1em; } .sm\:prose-sm ol { margin-top: 1.1428571em; margin-bottom: 1.1428571em; } .sm\:prose-sm ul { margin-top: 1.1428571em; margin-bottom: 1.1428571em; } .sm\:prose-sm li { margin-top: 0.2857143em; margin-bottom: 0.2857143em; } .sm\:prose-sm ol > li { padding-left: 1.5714286em; } .sm\:prose-sm ol > li::before { left: 0; } .sm\:prose-sm ul > li { padding-left: 1.5714286em; } .sm\:prose-sm ul > li::before { height: 0.3571429em; width: 0.3571429em; top: calc(0.8571429em - 0.1785714em); left: 0.2142857em; } .sm\:prose-sm > ul > li p { margin-top: 0.5714286em; margin-bottom: 0.5714286em; } .sm\:prose-sm > ul > li > *:first-child { margin-top: 1.1428571em; } .sm\:prose-sm > ul > li > *:last-child { margin-bottom: 1.1428571em; } .sm\:prose-sm > ol > li > *:first-child { margin-top: 1.1428571em; } .sm\:prose-sm > ol > li > *:last-child { margin-bottom: 1.1428571em; } .sm\:prose-sm ul ul, .sm\:prose-sm ul ol, .sm\:prose-sm ol ul, .sm\:prose-sm ol ol { margin-top: 0.5714286em; margin-bottom: 0.5714286em; } .sm\:prose-sm hr { margin-top: 2.8571429em; margin-bottom: 2.8571429em; } .sm\:prose-sm hr + * { margin-top: 0; } .sm\:prose-sm h2 + * { margin-top: 0; } .sm\:prose-sm h3 + * { margin-top: 0; } .sm\:prose-sm h4 + * { margin-top: 0; } .sm\:prose-sm table { font-size: 0.8571429em; line-height: 1.5; } .sm\:prose-sm thead th { padding-right: 1em; padding-bottom: 0.6666667em; padding-left: 1em; } .sm\:prose-sm thead th:first-child { padding-left: 0; } .sm\:prose-sm thead th:last-child { padding-right: 0; } .sm\:prose-sm tbody td { padding-top: 0.6666667em; padding-right: 1em; padding-bottom: 0.6666667em; padding-left: 1em; } .sm\:prose-sm tbody td:first-child { padding-left: 0; } .sm\:prose-sm tbody td:last-child { padding-right: 0; } .sm\:prose-sm > :first-child { margin-top: 0; } .sm\:prose-sm > :last-child { margin-bottom: 0; } .sm\:prose-lg { font-size: 1.125rem; line-height: 1.7777778; } .sm\:prose-lg p { margin-top: 1.3333333em; margin-bottom: 1.3333333em; } .sm\:prose-lg [class~="lead"] { font-size: 1.2222222em; line-height: 1.4545455; margin-top: 1.0909091em; margin-bottom: 1.0909091em; } .sm\:prose-lg blockquote { margin-top: 1.6666667em; margin-bottom: 1.6666667em; padding-left: 1em; } .sm\:prose-lg h1 { font-size: 2.6666667em; margin-top: 0; margin-bottom: 0.8333333em; line-height: 1; } .sm\:prose-lg h2 { font-size: 1.6666667em; margin-top: 1.8666667em; margin-bottom: 1.0666667em; line-height: 1.3333333; } .sm\:prose-lg h3 { font-size: 1.3333333em; margin-top: 1.6666667em; margin-bottom: 0.6666667em; line-height: 1.5; } .sm\:prose-lg h4 { margin-top: 1.7777778em; margin-bottom: 0.4444444em; line-height: 1.5555556; } .sm\:prose-lg img { margin-top: 1.7777778em; margin-bottom: 1.7777778em; } .sm\:prose-lg video { margin-top: 1.7777778em; margin-bottom: 1.7777778em; } .sm\:prose-lg figure { margin-top: 1.7777778em; margin-bottom: 1.7777778em; } .sm\:prose-lg figure > * { margin-top: 0; margin-bottom: 0; } .sm\:prose-lg figure figcaption { font-size: 0.8888889em; line-height: 1.5; margin-top: 1em; } .sm\:prose-lg code { font-size: 0.8888889em; } .sm\:prose-lg h2 code { font-size: 0.8666667em; } .sm\:prose-lg h3 code { font-size: 0.875em; } .sm\:prose-lg pre { font-size: 0.8888889em; line-height: 1.75; margin-top: 2em; margin-bottom: 2em; border-radius: 0.375rem; padding-top: 1em; padding-right: 1.5em; padding-bottom: 1em; padding-left: 1.5em; } .sm\:prose-lg ol { margin-top: 1.3333333em; margin-bottom: 1.3333333em; } .sm\:prose-lg ul { margin-top: 1.3333333em; margin-bottom: 1.3333333em; } .sm\:prose-lg li { margin-top: 0.6666667em; margin-bottom: 0.6666667em; } .sm\:prose-lg ol > li { padding-left: 1.6666667em; } .sm\:prose-lg ol > li::before { left: 0; } .sm\:prose-lg ul > li { padding-left: 1.6666667em; } .sm\:prose-lg ul > li::before { width: 0.3333333em; height: 0.3333333em; top: calc(0.8888889em - 0.1666667em); left: 0.2222222em; } .sm\:prose-lg > ul > li p { margin-top: 0.8888889em; margin-bottom: 0.8888889em; } .sm\:prose-lg > ul > li > *:first-child { margin-top: 1.3333333em; } .sm\:prose-lg > ul > li > *:last-child { margin-bottom: 1.3333333em; } .sm\:prose-lg > ol > li > *:first-child { margin-top: 1.3333333em; } .sm\:prose-lg > ol > li > *:last-child { margin-bottom: 1.3333333em; } .sm\:prose-lg ul ul, .sm\:prose-lg ul ol, .sm\:prose-lg ol ul, .sm\:prose-lg ol ol { margin-top: 0.8888889em; margin-bottom: 0.8888889em; } .sm\:prose-lg hr { margin-top: 3.1111111em; margin-bottom: 3.1111111em; } .sm\:prose-lg hr + * { margin-top: 0; } .sm\:prose-lg h2 + * { margin-top: 0; } .sm\:prose-lg h3 + * { margin-top: 0; } .sm\:prose-lg h4 + * { margin-top: 0; } .sm\:prose-lg table { font-size: 0.8888889em; line-height: 1.5; } .sm\:prose-lg thead th { padding-right: 0.75em; padding-bottom: 0.75em; padding-left: 0.75em; } .sm\:prose-lg thead th:first-child { padding-left: 0; } .sm\:prose-lg thead th:last-child { padding-right: 0; } .sm\:prose-lg tbody td { padding-top: 0.75em; padding-right: 0.75em; padding-bottom: 0.75em; padding-left: 0.75em; } .sm\:prose-lg tbody td:first-child { padding-left: 0; } .sm\:prose-lg tbody td:last-child { padding-right: 0; } .sm\:prose-lg > :first-child { margin-top: 0; } .sm\:prose-lg > :last-child { margin-bottom: 0; } .sm\:prose-xl { font-size: 1.25rem; line-height: 1.8; } .sm\:prose-xl p { margin-top: 1.2em; margin-bottom: 1.2em; } .sm\:prose-xl [class~="lead"] { font-size: 1.2em; line-height: 1.5; margin-top: 1em; margin-bottom: 1em; } .sm\:prose-xl blockquote { margin-top: 1.6em; margin-bottom: 1.6em; padding-left: 1.0666667em; } .sm\:prose-xl h1 { font-size: 2.8em; margin-top: 0; margin-bottom: 0.8571429em; line-height: 1; } .sm\:prose-xl h2 { font-size: 1.8em; margin-top: 1.5555556em; margin-bottom: 0.8888889em; line-height: 1.1111111; } .sm\:prose-xl h3 { font-size: 1.5em; margin-top: 1.6em; margin-bottom: 0.6666667em; line-height: 1.3333333; } .sm\:prose-xl h4 { margin-top: 1.8em; margin-bottom: 0.6em; line-height: 1.6; } .sm\:prose-xl img { margin-top: 2em; margin-bottom: 2em; } .sm\:prose-xl video { margin-top: 2em; margin-bottom: 2em; } .sm\:prose-xl figure { margin-top: 2em; margin-bottom: 2em; } .sm\:prose-xl figure > * { margin-top: 0; margin-bottom: 0; } .sm\:prose-xl figure figcaption { font-size: 0.9em; line-height: 1.5555556; margin-top: 1em; } .sm\:prose-xl code { font-size: 0.9em; } .sm\:prose-xl h2 code { font-size: 0.8611111em; } .sm\:prose-xl h3 code { font-size: 0.9em; } .sm\:prose-xl pre { font-size: 0.9em; line-height: 1.7777778; margin-top: 2em; margin-bottom: 2em; border-radius: 0.5rem; padding-top: 1.1111111em; padding-right: 1.3333333em; padding-bottom: 1.1111111em; padding-left: 1.3333333em; } .sm\:prose-xl ol { margin-top: 1.2em; margin-bottom: 1.2em; } .sm\:prose-xl ul { margin-top: 1.2em; margin-bottom: 1.2em; } .sm\:prose-xl li { margin-top: 0.6em; margin-bottom: 0.6em; } .sm\:prose-xl ol > li { padding-left: 1.8em; } .sm\:prose-xl ol > li::before { left: 0; } .sm\:prose-xl ul > li { padding-left: 1.8em; } .sm\:prose-xl ul > li::before { width: 0.35em; height: 0.35em; top: calc(0.9em - 0.175em); left: 0.25em; } .sm\:prose-xl > ul > li p { margin-top: 0.8em; margin-bottom: 0.8em; } .sm\:prose-xl > ul > li > *:first-child { margin-top: 1.2em; } .sm\:prose-xl > ul > li > *:last-child { margin-bottom: 1.2em; } .sm\:prose-xl > ol > li > *:first-child { margin-top: 1.2em; } .sm\:prose-xl > ol > li > *:last-child { margin-bottom: 1.2em; } .sm\:prose-xl ul ul, .sm\:prose-xl ul ol, .sm\:prose-xl ol ul, .sm\:prose-xl ol ol { margin-top: 0.8em; margin-bottom: 0.8em; } .sm\:prose-xl hr { margin-top: 2.8em; margin-bottom: 2.8em; } .sm\:prose-xl hr + * { margin-top: 0; } .sm\:prose-xl h2 + * { margin-top: 0; } .sm\:prose-xl h3 + * { margin-top: 0; } .sm\:prose-xl h4 + * { margin-top: 0; } .sm\:prose-xl table { font-size: 0.9em; line-height: 1.5555556; } .sm\:prose-xl thead th { padding-right: 0.6666667em; padding-bottom: 0.8888889em; padding-left: 0.6666667em; } .sm\:prose-xl thead th:first-child { padding-left: 0; } .sm\:prose-xl thead th:last-child { padding-right: 0; } .sm\:prose-xl tbody td { padding-top: 0.8888889em; padding-right: 0.6666667em; padding-bottom: 0.8888889em; padding-left: 0.6666667em; } .sm\:prose-xl tbody td:first-child { padding-left: 0; } .sm\:prose-xl tbody td:last-child { padding-right: 0; } .sm\:prose-xl > :first-child { margin-top: 0; } .sm\:prose-xl > :last-child { margin-bottom: 0; } .sm\:prose-2xl { font-size: 1.5rem; line-height: 1.6666667; } .sm\:prose-2xl p { margin-top: 1.3333333em; margin-bottom: 1.3333333em; } .sm\:prose-2xl [class~="lead"] { font-size: 1.25em; line-height: 1.4666667; margin-top: 1.0666667em; margin-bottom: 1.0666667em; } .sm\:prose-2xl blockquote { margin-top: 1.7777778em; margin-bottom: 1.7777778em; padding-left: 1.1111111em; } .sm\:prose-2xl h1 { font-size: 2.6666667em; margin-top: 0; margin-bottom: 0.875em; line-height: 1; } .sm\:prose-2xl h2 { font-size: 2em; margin-top: 1.5em; margin-bottom: 0.8333333em; line-height: 1.0833333; } .sm\:prose-2xl h3 { font-size: 1.5em; margin-top: 1.5555556em; margin-bottom: 0.6666667em; line-height: 1.2222222; } .sm\:prose-2xl h4 { margin-top: 1.6666667em; margin-bottom: 0.6666667em; line-height: 1.5; } .sm\:prose-2xl img { margin-top: 2em; margin-bottom: 2em; } .sm\:prose-2xl video { margin-top: 2em; margin-bottom: 2em; } .sm\:prose-2xl figure { margin-top: 2em; margin-bottom: 2em; } .sm\:prose-2xl figure > * { margin-top: 0; margin-bottom: 0; } .sm\:prose-2xl figure figcaption { font-size: 0.8333333em; line-height: 1.6; margin-top: 1em; } .sm\:prose-2xl code { font-size: 0.8333333em; } .sm\:prose-2xl h2 code { font-size: 0.875em; } .sm\:prose-2xl h3 code { font-size: 0.8888889em; } .sm\:prose-2xl pre { font-size: 0.8333333em; line-height: 1.8; margin-top: 2em; margin-bottom: 2em; border-radius: 0.5rem; padding-top: 1.2em; padding-right: 1.6em; padding-bottom: 1.2em; padding-left: 1.6em; } .sm\:prose-2xl ol { margin-top: 1.3333333em; margin-bottom: 1.3333333em; } .sm\:prose-2xl ul { margin-top: 1.3333333em; margin-bottom: 1.3333333em; } .sm\:prose-2xl li { margin-top: 0.5em; margin-bottom: 0.5em; } .sm\:prose-2xl ol > li { padding-left: 1.6666667em; } .sm\:prose-2xl ol > li::before { left: 0; } .sm\:prose-2xl ul > li { padding-left: 1.6666667em; } .sm\:prose-2xl ul > li::before { width: 0.3333333em; height: 0.3333333em; top: calc(0.8333333em - 0.1666667em); left: 0.25em; } .sm\:prose-2xl > ul > li p { margin-top: 0.8333333em; margin-bottom: 0.8333333em; } .sm\:prose-2xl > ul > li > *:first-child { margin-top: 1.3333333em; } .sm\:prose-2xl > ul > li > *:last-child { margin-bottom: 1.3333333em; } .sm\:prose-2xl > ol > li > *:first-child { margin-top: 1.3333333em; } .sm\:prose-2xl > ol > li > *:last-child { margin-bottom: 1.3333333em; } .sm\:prose-2xl ul ul, .sm\:prose-2xl ul ol, .sm\:prose-2xl ol ul, .sm\:prose-2xl ol ol { margin-top: 0.6666667em; margin-bottom: 0.6666667em; } .sm\:prose-2xl hr { margin-top: 3em; margin-bottom: 3em; } .sm\:prose-2xl hr + * { margin-top: 0; } .sm\:prose-2xl h2 + * { margin-top: 0; } .sm\:prose-2xl h3 + * { margin-top: 0; } .sm\:prose-2xl h4 + * { margin-top: 0; } .sm\:prose-2xl table { font-size: 0.8333333em; line-height: 1.4; } .sm\:prose-2xl thead th { padding-right: 0.6em; padding-bottom: 0.8em; padding-left: 0.6em; } .sm\:prose-2xl thead th:first-child { padding-left: 0; } .sm\:prose-2xl thead th:last-child { padding-right: 0; } .sm\:prose-2xl tbody td { padding-top: 0.8em; padding-right: 0.6em; padding-bottom: 0.8em; padding-left: 0.6em; } .sm\:prose-2xl tbody td:first-child { padding-left: 0; } .sm\:prose-2xl tbody td:last-child { padding-right: 0; } .sm\:prose-2xl > :first-child { margin-top: 0; } .sm\:prose-2xl > :last-child { margin-bottom: 0; } .sm\:prose-red a { color: #dc2626; } .sm\:prose-red a code { color: #dc2626; } .sm\:prose-yellow a { color: #d97706; } .sm\:prose-yellow a code { color: #d97706; } .sm\:prose-green a { color: #059669; } .sm\:prose-green a code { color: #059669; } .sm\:prose-blue a { color: #2563eb; } .sm\:prose-blue a code { color: #2563eb; } .sm\:prose-indigo a { color: #4f46e5; } .sm\:prose-indigo a code { color: #4f46e5; } .sm\:prose-purple a { color: #7c3aed; } .sm\:prose-purple a code { color: #7c3aed; } .sm\:prose-pink a { color: #db2777; } .sm\:prose-pink a code { color: #db2777; } ```

There are 37 colors set here... and overriding these doesn't work unless you BOTH have !important AND use the correct @media rule for EACH one.

nnooney commented 3 years ago

I notice that you don't specify the dark variant in your tailwind.config.js; does adding this help? This is the outline of my config file, which supports dark mode styling:

module.exports = {
  darkMode: 'media',
  theme: {
    extend: {
      typography: (theme) => ({
        DEFAULT: {
          ...
        },
        'dark': {
          ...
        }
      }),
    },
  },
  variants: {
    extend: {
      typography: ['dark'],
    },
  },
  plugins: [
    require('@tailwindcss/typography'),
  ],
}

I'm using the media version of dark mode instead of the class based version. My main code uses <article class="prose dark:prose-dark"> to establish dark mode. I also override all colors with these selectors:

css: {
  color: ...,
  a: {
    color: ...,
    code: { color: ... },
  },
  blockquote: {
    borderLeftColor: ...,
    color: ...,
  },
  code: {
    color: ...,
  },
  figure: {
    figcaption: { color: ... },
  },
  h1: { color: ... },
  h2: { color: ... },
  h3: { color: ... },
  h4: { color: ... },
  hr: { borderColor: ... },
  ol: {
    li: {
      '&:before': { color: ... },
    }
  },
  strong: { color: ... },
  thead: {
    borderBottomColor: ...,
    color: ...,
  },
  tbody: {
    tr: {
      borderBottomColor: ...,
    },
  },
  ul: {
    li: {
      '&:before': { backgroundColor: ... },
    }
  },
}
justingolden21 commented 3 years ago

Thank you for your reply. My tailwind.config.js has darkMode set to 'class' as seen above as I want to have the ability to toggle dark mode programmatically (by toggling the dark class with JS) (so that the user can toggle a switch). I'll have to try out your implementation; thank you for sharing that. I'm currently using a rather ugly solution by putting this in base with !important:

@layer base {
    p, h1, h2, h3, h4, input, label, li, th, td, a, code, strong, li::before, figcaption {
        color: black !important;
    }
    .dark p, .dark h1, .dark h2, .dark h3, .dark h4, .dark input, .dark label, .dark li, .dark th, .dark td, .dark a, .dark code, .dark strong, .dark li::before, .dark figcaption {
        color: white !important;
    }
    .hover\:text-white:hover {
        color: white !important;
    }
    .hover\:text-black:hover {
        color: black !important;
    }
    *:not(h1):not(h2):not(h3):not(h4) {
        font-family: Open Sans;
    }
    h1, h2, h3, h4 {
        font-family: Arvo;
    }
}

But it does work. I just might have problems with it later and I can't imagine this is the intended use. Thank you again.

pbrazdil commented 3 years ago

Same use case and encountering the same issue. What's the correct approach? This solution seem rather hacky.

Paul333333 commented 3 years ago

It appears the color modifiers get overruled by the responsive breakpoints, because the responsive breakpoints include link colors as well and win over the simple color modifiers.

mygiftcardsite

MichaelAllenWarner commented 3 years ago

Yes, customizing the color-scheme is a pain.

I propose an option to simply suppress the default color rules entirely.

Enabling such an option would mean sacrificing different shades for bullets and the like, but as nice as the default color scheme is, I'd gladly trade those subtleties for the ability to do something like <div class="prose prose-white">, with a config that could be as simple as:

typography: {
  white: {
    css: {
      color: 'white',
      'a:hover': {
        color: 'whatever'
      }
    }
  }
}
istr commented 3 years ago

I would tend to say that the best option here would be to change the default to not to mess with colors per default. That is to say, just stick with inherit (i.e. do not set colors) and add a prose-gray modifier. With this approach typography would not break other color scheme modifications and it would be easy to mimic the "gray is default" behavior.

Default (inherit, leave colors untouched) <div class="prose">

Gray <div class="prose prose-gray">

All darkmode / themeswitch issues will be a goner with this simple twist.

MichaelAllenWarner commented 3 years ago

@istr Consider contributing to the discussion about this that I started here.

FWIW, I've been using this snippet (in DEFAULT.css) to "undo" most of Typography's default color scheme:

[
  [
    '[class~="lead"]',
    'strong',
    'ol > li::before',
    'blockquote',
    'h1',
    'h2',
    'h3',
    'h4',
    'figure figcaption',
    'code',
    'a code',
    'thead'
  ].join(', ')
]: {
  color: 'inherit'
},

'ul > li::before': {
  backgroundColor: 'currentColor'
},

[
  [
    'hr',
    'blockquote',
    'thead',
    'tbody tr'
  ].join(', ')
]: {
  borderColor: 'currentColor'
},

(watch out for that standalone ul > li::before key, though—easy to accidentally duplicate it). The only colors I exclude from this "reset" are the a and a:hover text-colors, and the pre text-color and background-color.

simonswiss commented 2 years ago

Going to close this issue since the new Typography plugin (v0.5) changes a lot of that, with a new customization API directly in the markup, and the "not-prose" class to opt-out of default styles where needed within a prose block.

Here's a link to the release blog post for some context:

https://tailwindcss.com/blog/tailwindcss-typography-v0-5

rene-qore commented 9 months ago

I would tend to say that the best option here would be to change the default to not to mess with colors per default. That is to say, just stick with inherit (i.e. do not set colors) and add a prose-gray modifier. With this approach typography would not break other color scheme modifications and it would be easy to mimic the "gray is default" behavior.

Default (inherit, leave colors untouched) <div class="prose">

Gray <div class="prose prose-gray">

All darkmode / themeswitch issues will be a goner with this simple twist.

Somehow this is ignored when changed the default "gray" colors?