how to pass dynamically text at pseudo class in tailwind css – after:content-[?] in react js inside .map

huangapple go评论65阅读模式
英文:

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}]  &lt;----- 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 = [
    &quot;Web Design&quot;,
    &quot;Development&quot;,
    &quot;Illustration&quot;,
    &quot;Product Design&quot;,
    &quot;Social Media&quot;,
];
&lt;ul className=&#39;flex flex-col gap-5 text-[85px]&#39;&gt;
{
  data.map(item =&gt;
	&lt;li
	  key={item}
	  className={`cursor-pointer relative
	  after:content-[&#39;${item}&#39;]  &lt;----- this approach is not working...! Why?
	  after:absolute
	  after:right-0
	  after:text-red-200 `}
	&gt;

	  {item}

	&lt;/li&gt;
  )
}
&lt;/ul&gt;

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

&lt;ul className=&#39;flex flex-col gap-5 text-[85px]&#39;&gt;
{
  data.map(item =&gt;
    &lt;li
      key={item}
      after-dynamic-value={item}
      className={`cursor-pointer relative
      after:content-[attr(after-dynamic-value)]  &lt;----- this approach is working...
      after:absolute
      after:right-0
      after:text-red-200 `}
    &gt;

      {item}

    &lt;/li&gt;
  )
}
&lt;/ul&gt;

huangapple
  • 本文由 发表于 2023年3月7日 20:58:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75662277.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定