Closed justingolden21 closed 2 years ago
Screenshot of what I mean:
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
:
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...
Here's what I mean by having to override every single default style from this typography plugin:
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.
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: ... },
}
},
}
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.
Same use case and encountering the same issue. What's the correct approach? This solution seem rather hacky.
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.
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'
}
}
}
}
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.
@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.
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:
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?
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 ofprose
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 tohtml
works for the background color, but the individualprose
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:
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
default.html
post.html
Thanks in advance for any help on this...