英文:
how to pass dynamically text at pseudo class in tailwind css - after:content-[?] in react js inside .map
问题
仅翻译代码部分:
const data = [
"Web Design",
"Development",
"Illustration",
"Product Design",
"Social Media",
];
<ul className='flex flex-col gap-5 text-[85px]'>
{
data.map(item =>
<li
key={item}
className={`cursor-pointer relative
after:content-[${item}] <----- this approach is not working...! Why?
after:absolute
after:right-0
after:text-red-200 `}
>
{item}
</li>
)
}
</ul>
虽然我尝试了这种方法...
after:content-[${item}]
英文:
By hovering at the text ::after pseudo-class content is going to be visible, but by just looking or testing, I wouldn't print that text content in the browser by this approach in tailwind-css with react-js inside .map()
const data = [
"Web Design",
"Development",
"Illustration",
"Product Design",
"Social Media",
];
<ul className='flex flex-col gap-5 text-[85px]'>
{
data.map(item =>
<li
key={item}
className={`cursor-pointer relative
after:content-['${item}'] <----- this approach is not working...! Why?
after:absolute
after:right-0
after:text-red-200 `}
>
{item}
</li>
)
}
</ul>
though I try this approach also...
after:content-[${item}]
答案1
得分: 6
<ul className='flex flex-col gap-5 text-[85px]'>
{
data.map(item =>
<li
key={item}
after-dynamic-value={item}
className={`cursor-pointer relative
after:content-[attr(after-dynamic-value)] // 这个方法有效...
after:absolute
after:right-0
after:text-red-200 `}
>
{item}
</li>
)
}
</ul>
英文:
after more R&D find a way to pass dynamic data as value to (::after) pseudo-class in tailwind css
<ul className='flex flex-col gap-5 text-[85px]'>
{
data.map(item =>
<li
key={item}
after-dynamic-value={item}
className={`cursor-pointer relative
after:content-[attr(after-dynamic-value)] <----- this approach is working...
after:absolute
after:right-0
after:text-red-200 `}
>
{item}
</li>
)
}
</ul>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论