我有来自以下按钮的输入:
<div className="relative">
<input
data-testid="toggle-input-checkbox"
onChange={handleOnChange}
id={id}
type="checkbox"
className="sr-only"
checked={isChecked}
/>
<div className="base w-9 h-3.5 bg-grey-6 rounded-full shadow-inner" />
<div className="dot bg-white absolute w-5 h-5 rounded-full shadow -left-1 -top-1 transition" />
</div>和toggle.css:
input:checked ~ .base {
background-color: #46e18c;
}
input:checked ~ .dot {
transform: translateX(100%);
}在Tailwind中是否有一种方法可以避免使用自定义类来实现所需的样式?
发布于 2022-01-18 16:04:02
使用peer修饰符,如下所示:
// Add `peer` to the element which state you want to track
<input type="checkbox" checked class="peer" />
// Then use `peer-*` modifiers on the target element which style you want to change
<div class="peer-checked:text-red-500">Sibling</div>https://stackoverflow.com/questions/70758526
复制相似问题