-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[Feature Proposal] Content utility for generating pseudo elements #1306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Using Tailwind class name conventionsWhat about this approach? It's what I'm working on for my scss utility library. // style.css
/**
* 1. Apply text content by retrieving the value from `data-content` HTML attribute.
* If left empty fallback to an empty string.
* 2. Property to apply to the generated content. `display`, `border`, etc.
*/
.before\:block::before {
content: attr(data-content, ''); /* 1 */
display: block; /* 2 */
} <!-- index.html -->
<button class="before:block" data-content="👍">
Like
</button> |
Oh interesting, I always forget that the <button data-content="🎉">
Party!
</button> button:before {
@apply block content;
} Update: It looks like the fallback content is not reliable yet, we might have to look into this a bit more to find a useful way for it to work with data attributes Update 2: Actually since we'd just be defaulting to an empty string, this appears to work without relying on experimental properties. content: attr(data-content); |
It could be anything we want to: I forgot the second argument for fallback is no supported by any browser. I'm going to test it in codepen and I'll let you know what I came up with. |
Ok, found it/**
* 1. Fallback content
* 2. Apply text content by retrieving the value
* from `data-content` HTML attribute.
* 3. Property to apply to the generated content.
* `display`, `border`, etc.
*/
.before\:inline-block::before {
content: ''; /* 1 */
content: attr(data-content); /* 2 */
display: inline-block; /* 3 */
} If <button class="before:inline-block" data-content="👍">
Like
</button> Update: .before\:inline-block::before {
content: attr(data-content);
display: inline-block;
} |
Yeap, you're right I've just found out about the fallback support. Your demo works fine, as does mine. Take your flavor 😁 |
You are right, we don't need From the W3C spec
|
Instead of using I'm always adding additional css because of the generated content tricks I like to do. |
Cool, I'm glad the default |
We could use |
Maybe this could all just be part of the configuration, I can think of a couple custom
Obviously we wouldn't need these all on by default, but I think it would be a helpful feature to have 🙂 |
I think Also it should be possible to combine .before\:inline-block::before {
content: attr(data-before);
display: inline-block;
}
.after\:inline-block::after {
content: attr(data-after);
display: inline-block;
} <div class="before:inline-block after:inline-block" data-before="👍" data-after="👎">
Can I get a like?
</div> @scottbedard Zero width spaces would be possible with <div class="before:inline-block after:inline-block" data-before="​"></div> |
I use pseudo-elements very often. After using Hucssley which makes styling pseudo-elements as easy as any other element, it's a pain to not have this in Tailwind projects. (Full disclosure, I've contributed in a very minor way to Hucssley) |
I'm closing this issue, if anyone is looking for this functionality check out the following plugin |
For future reference, thanks to JIT we now have |
The problem
With Tailwind, it feels ugly when I have to "leave Tailwind", and fall back to writing traditional css. One situation where I frequently find myself doing this adding empty content attributes to generate pseudo elements.
While not being the biggest deal, the mixed approaches feels off to me. I think it would be handy and more ergonomic if we could do something like this...
Pros
Cons
Again, not the most important utility, but I've found myself needing it on multiple projects, and think if would be handy to have out of the box.
The text was updated successfully, but these errors were encountered: