Replies: 10 comments 26 replies
-
Yeah. I'd also like to know how to use this in tailwind |
Beta Was this translation helpful? Give feedback.
-
Me too :D Is there a 3rd npm pack for this ? |
Beta Was this translation helpful? Give feedback.
-
I am in too. |
Beta Was this translation helpful? Give feedback.
-
I found this discussion looking to see if there was any plan about adding it in core, but it's already a tailwind plugin that you can find here. https://github.com/croutonn/tailwindcss-pseudo-elements I'd still love if it wasn't a plugin and to see that in core... mostly about peace of mind when comes around time to upgrade tailwind and such. I use pseudo elements in every single one of my projects and it's now become the first thing that makes me write an actual stylesheet whereas tailwind generates so many useful classes already that I usually wouldn't even need to. 😂 |
Beta Was this translation helpful? Give feedback.
-
You can do this with custom variants. module.exports = {
// ...
plugins: [
plugin(({ addVariant, e }) => {
addVariant('before', ({ modifySelectors, separator }) => {
modifySelectors(({ className }) => {
return `.${e(`before${separator}${className}`)}::before`;
});
});
addVariant('after', ({ modifySelectors, separator }) => {
modifySelectors(({ className }) => {
return `.${e(`after${separator}${className}`)}::after`;
});
});
}),
plugin(({ addUtilities }) => {
const contentUtilities = {
'.content': {
content: 'attr(data-content)',
},
'.content-before': {
content: 'attr(data-before)',
},
'.content-after': {
content: 'attr(data-after)',
},
};
addUtilities(contentUtilities, ['before', 'after']);
}),
],
}; Then, use like this: <p data-content="💙" class="before:content after:content">
<!-- -->
</p>
<p data-before="💙" data-after="💛" class="before:content-before after:content-after">
<!-- -->
</p> |
Beta Was this translation helpful? Give feedback.
-
Personal recommendation is to use real elements, not pseudo elements. Aside from bullets in the typography plugin, I haven’t used a pseudo element since initially creating Tailwind. Haven’t run into a single situation where I couldn’t just use a real element with “aria-hidden” and use regular Tailwind utilities to style it. |
Beta Was this translation helpful? Give feedback.
-
I created a plug-in for this that takes advantage of the new JIT mode. (You can write custom content for the pseudo elements and the variants work beautifully with whatever styling you'd need) https://www.npmjs.com/package/@shimyshack/tailwindcss-pseudo-element-plugin |
Beta Was this translation helpful? Give feedback.
-
I just discover this conversation and it's very interesting.
My goal is to implement it exclusively with tailwind and I'm using react. |
Beta Was this translation helpful? Give feedback.
-
In React I just combine Styled Components with Twin Macro. Having in the end something like this:
|
Beta Was this translation helpful? Give feedback.
-
I am using Tailwind CSS for the first time and I am liking the experience so far. I came onto a situation that is not covered: the use of pseudo-elements, in this case before and after. A simple example could be:
CSS
HTML
Beta Was this translation helpful? Give feedback.
All reactions