【发布时间】:2021-10-01 00:02:51
【问题描述】:
我使用 tailwind 创建了一个自定义复选框(作为 react 项目中的一个组件)。现在我想在检查之前和检查之后更改复选框的背景颜色。 这就是我要的:
我想知道如何在 tailwind.css 中更改此颜色 这是复选框代码:
<div className="check-box">
<input type="checkbox"
value={ value }
id={ id }
name={ name }
onBlur={ onBlur }
className="absolute h-6 w-6 cursor-pointer" onChange={ onChange } />
<div className="bg-xaplink_gray_1 border-2 border- xaplink_gray_3 w-6 h-6 flex flex-shrink-0 justify-center items-center mr-2 focus-within:border-xaplink_black_2">
<svg className="fill-current hidden w-4 h-4 text-xaplink_white pointer-events-none" version="1.1" viewBox="0 0 17 12" xmlns="http://www.w3.org/2000/svg">
<g fill="none" fillRule="evenodd">
<g transform="translate(-9 -11)" fill="#FFFF" fillRule="nonzero">
<path d="m25.576 11.414c0.56558 0.55188 0.56558 1.4439 0 1.9961l-9.404 9.176c-0.28213 0.27529-0.65247 0.41385-1.0228 0.41385-0.37034 0-0.74068-0.13855-1.0228-0.41385l-4.7019-4.588c-0.56584-0.55188-0.56584-1.4442 0-1.9961 0.56558-0.55214 1.4798-0.55214 2.0456 0l3.679 3.5899 8.3812-8.1779c0.56558-0.55214 1.4798-0.55214 2.0456 0z" />
</g>
</g>
</svg>
</div>
</div>
这是我在 react 中的复选框组件:
import React, { useEffect, useState } from "react";
const XCheckBox = ({ value, id, name, onBlur,label, side, error, touched, onChange }) => {
return (
<>
<div className=" flex flex-row gap-5 py-2">
<div className="check-box">
<input type="checkbox"
value={ value }
id={ id }
name={ name }
onBlur={ onBlur }
className="absolute h-6 w-6 cursor-pointer" onChange={ onChange } />
<div className="bg-xaplink_gray_1 border-2 border-xaplink_gray_3 w-6 h-6 flex flex-shrink-0 justify-center items-center mr-2 focus-within:border-xaplink_black_2">
<svg className="fill-current hidden w-4 h-4 text-xaplink_white pointer-events-none" version="1.1" viewBox="0 0 17 12" xmlns="http://www.w3.org/2000/svg">
<g fill="none" fillRule="evenodd">
<g transform="translate(-9 -11)" fill="#FFFF" fillRule="nonzero">
<path d="m25.576 11.414c0.56558 0.55188 0.56558 1.4439 0 1.9961l-9.404 9.176c-0.28213 0.27529-0.65247 0.41385-1.0228 0.41385-0.37034 0-0.74068-0.13855-1.0228-0.41385l-4.7019-4.588c-0.56584-0.55188-0.56584-1.4442 0-1.9961 0.56558-0.55214 1.4798-0.55214 2.0456 0l3.679 3.5899 8.3812-8.1779c0.56558-0.55214 1.4798-0.55214 2.0456 0z" />
</g>
</g>
</svg>
</div>
</div>
</div>
<div>
{ touched && error ? (
<p className="text-xs pl-2 text-xaplink_red_2 mb-4">{ error }</p>
) : null }
</div>
</>
);
};
export default XCheckBox;
【问题讨论】:
标签: reactjs tailwind-css