Comments (2)
Hey! So I totally understand why this is unexpected behavior...you're expecting the not-prose
class to completely disable all the prose styles. And while this generally works, it falls apart a bit with the root styles that set the font size and line height. This is because the font-size
and line-height
properties are inherited, which means they cascade to child elements.
I spent a bunch of time on this today, and the only way to reliably prevent the prose styles from being applied to the not-prose
element would be to never put them on the root element to begin with and only apply the font size and line height to each direct child that doesn't have the not-prose
class on it. Something like this:
.prose-lg > :where(:not([class~="not-prose"])) {
font-size: 18px;
}
The only problem with that solution is that today not-prose
works on any descendant element, not just direct children, so this would be a breaking change. For example, if we made this change, this code that has not-prose
applied to a div
within an article
would break:
<div class="prose">
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit...</p>
<article>
<div class="not-prose">
I am not styled with prose
</div>
</article>
</div>
An alternative solution could be to select all of the descendants, not just the direct children. Something like this:
.prose :where(h1:not([class~="not-prose"] *)) {
font-size: 30px;
}
.prose-lg :where(:not([class~="not-prose"])) {
font-size: 18px;
}
.prose-lg :where(h1:not([class~="not-prose"] *)) {
font-size: 36px;
}
This works great until you add a child element to something that the typography plugin styles — such as an h1
, p
, li
, etc. The child element would get targeted by the prose-lg
selector (because we're using *
), which would result in the wrong styles being applied.
Using the example above, that would mean if you include a span
within an h1
, that span
would end up being 18px
instead of 36px
, which isn't what you want:
<div class="prose prose-lg">
<h1>Title <span class="text-gray-600">secondary</span></h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit...</p>
<div class="not-prose">I am not styled with prose</div>
</div>
Also worth noting that we can't simply reset not-prose
back to 1rem
(the Tailwind preflight default) because it's possible that someone has changed their root font size, or even the font size of the prose section.
CSS does have a new feature coming called scoped styles, which will make implementing not-prose
much, much easier, since we can limit prose
styles from inheriting into not-prose
:
@scope (.md\:prose-lg) to (.not-prose) {
:scope {
font-size: 1.125rem;
line-height: 1.7777778;
}
}
Unfortunately this feature is still very early on and isn't supported by any browsers yet.
My recommendation for you at this point would be to simply apply the correct font size (and line-height utility if needed) when using not-prose
:
<div class="prose md:prose-lg">
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit...</p>
<div class="not-prose md:text-base">I am not styled with prose</div>
</div>
Hope that helps!
from tailwindcss-typography.
@reinink thanks for such a detailed response! Yes, I came to the same conclusions, and using not-prose md:text-base
solves all issues. It can be mentioned in the docs, though.
from tailwindcss-typography.
Related Issues (20)
- Generated classes do not respect base tailwind.config "important" setting HOT 2
- Bottom margin is not reset for last child when redefined in lg prose HOT 2
- Wrong order of custom utilities and prose with variant HOT 3
- 0.5.10 causes '[class~=not-prose] *)):before' is not a valid selector HOT 5
- Peer dependency invalid version requirement HOT 1
- `prose-code` targets both inline and block code HOT 5
- Bad DX: [object Object] appearing in CSS when customizing typography
- Unable to change video size using prose-video:{utility} HOT 3
- Does not work on wechat webview HOT 1
- Numbered lists are being cut off HOT 1
- Markdown Rendered Graphs Overflows the Screen HOT 1
- Type error in the config: Binding element 'theme' implicitly has an 'any' type. HOT 2
- Links don't have a default hover state HOT 3
- Prose not formatting markdown tables correctly HOT 1
- The rendered image height is incorrect. HOT 2
- headings modifier does not work HOT 9
- Prose class adds inner border to specific font on Chrome HOT 2
- Different rendering on Firefox HOT 3
- @apply prose is failing the first- and last-child selectors HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tailwindcss-typography.