JIT: Add support for before/after pseudo-elements #4461
Merged
+130
−23
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for
::before
and::after
pseudo-elements, as well as thecontent
property to the JIT engine.Usage looks like this:
Any utility that is applied with a before/after variant automatically includes
content: ""
by default to avoid having to add that yourself every single time, so the rules above are actually generated like this:This means
content: ""
is going to be duplicated several times in your CSS if you use this feature, but I think it's worth it for the improved developer experience given how well that will ultimately compress.Out of the box,
content-none
is the only available preconfigured content utility. Those values can be of course extended in yourtailwind.config.js
file though, under thecontent
key.The
content
utilities have complete arbitrary value support though, which is where I think they are most useful:They even support stuff like the
attr
function, so you can reference a value stored in an attribute:I considered making this behavior the default with a fallback to an empty string if the attribute didn't exist, but ultimately decided against it since deciding on the name for the default attribute is tricky and introduces a lot of naming collision potential in people's real world projects.
As mentioned earlier, these features are JIT only.