[英]Tailwind.css — How to implement the last-child using Tailwind?
I have tried without success to implement the prefix last: as shown in the Tailwind.css documentation.我尝试过最后实现前缀,但没有成功:如 Tailwind.css 文档中所示。 Can anyone point out what I am doing wrong?
谁能指出我做错了什么? I cannot make this work.
我无法完成这项工作。
Thank you in advance.先感谢您。
React Component反应组件
{items.map((item, i) => {
return (
<li
key={i.toString()}
v-for="(item, i) in items"
className="pb-sm xl:pb-md last:pb-0" // This is the problematic fellow!
>
<div className="grid grid-cols-12">
<div className="col-start-2 col-span-10 md:col-start-2 md:col-span-8 pb-2 sm:pb-xs md:pb-xs lg:pb-xs xl:pb-0">
<div className="serif text-h5 xl:text-h4 lg:text-h4 md:text-h4 leading-snug xl:leading-tight lg:leading-tight md:leading-snug">
{item}
</div>
</div>
<div className="col-start-2 col-span-10 sm:col-start-5 sm:col-span-6 md:col-start-5 md:col-span-6 lg:col-start-5 lg:col-span-6 xl:col-start-5 xl:col-span-3 pb-xs sm:pb-xs">
<div className="text-p sm:text-p">{description[i]}</div>
</div>
</div>
</li>
)
})}
As of April 2022 (v 3.0.24)截至 2022 年 4 月 (v 3.0.24)
According to Tailwind's doc:根据 Tailwind 的文档:
Style an element when it is the first-child or last-child using the first and last modifiers
使用 first 和 last 修饰符为元素设置第一个或最后一个子元素的样式
Just use last:${yourClassName}
to target the last child in your case.只需使用
last:${yourClassName}
来定位您案例中的最后一个孩子。
Source: https://tailwindcss.com/docs/hover-focus-and-other-states#last资料来源: https://tailwindcss.com/docs/hover-focus-and-other-states#last
Not sure if you're using Tailwind v2.X
or v1.X
but you need to activate the variant for last
.不确定您使用的是 Tailwind
v2.X
还是v1.X
,但您需要为last
激活变体。 Here is a quote from the official v2 docs related page这是官方 v2 文档相关页面的引用
By default, the last-child variant is not enabled for any core plugins.
默认情况下,没有为任何核心插件启用 last-child 变体。
I've tried to make an example for you on https://play.tailwindcss.com/ but it doesn't work there.我试图在https://play.tailwindcss.com/上为您举个例子,但它在那里不起作用。 Meanwhile, I spin a Vite VueJS repo with the latest version of TW and it's working perfectly.
同时,我使用最新版本的 TW 旋转了一个 Vite VueJS 存储库,它运行良好。
So, this in your tailwind.config.js
should do the trick所以,这在你的
tailwind.config.js
中应该可以解决问题
module.exports = {
...
variants: {
extend: {
padding: ['last'],
}
},
...
}
v2's documentation is here and v1's is here . v2 的文档在这里,v1 的在这里。
Beware, the variants >> extend
is only available in the v2.请注意,
variants >> extend
仅在 v2 中可用。 If you're using v1, you can still override the whole padding
variant manually, not a big deal.如果您使用的是 v1,您仍然可以手动覆盖整个
padding
变体,这没什么大不了的。
PS: Tailwind's team fixed the issue already, damn ! PS:Tailwind 的团队已经解决了这个问题,该死!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.