در این آموزش، نحوه استفاده از کلاسهای تیلوند برای استایلدهی وضعیتهای مختلف یک فرم را بررسی خواهیم کرد. این کلاسها به شما امکان میدهند تا ظاهر فرم را بر اساس وضعیتهای مختلف آن مانند "hover"، "valid"، "invalid"، "focus" و موارد دیگر تنظیم کنید.
نمونه فرم
فرض کنید فرم زیر را داریم:
<form> <input type="text" name="username" required> <input type="email" name="email" required> <input type="password" name="password" required> <button type="submit">Submit</button> </form>
استایلدهی وضعیتها
hover استفاده کنید.<input type="text" name="username" required class="hover:bg-gray-200">
focus استفاده کنید.<input type="text" name="username" required class="focus:ring-2 focus:ring-blue-500">
valid استفاده کنید.<input type="email" name="email" required class="valid:text-green-500">
invalid استفاده کنید.<input type="password" name="password" required class="invalid:border-red-500">
in-range استفاده کنید.<input type="number" name="age" min="18" max="65" class="in-range:text-green-500">
out-of-range استفاده کنید.<input type="number" name="age" min="18" max="65" class="out-of-range:text-red-500">
focus-within استفاده کنید.<label class="focus-within:text-blue-500"> <input type="text" name="username" required> </label>
focus-visible استفاده کنید.<input type="text" name="username" required class="focus-visible:ring-2 focus-visible:ring-blue-500">
enabled استفاده کنید.<button type="submit" class="enabled:bg-blue-500">Submit</button>
disabled استفاده کنید.HTML
<button type="submit" disabled class="disabled:bg-gray-300">Submit</button>
استایلدهی هنگام ضروری (required):برای اعمال استایل زمانی که عنصر ضروری است، از کلاس required استفاده کنید.
HTML
<input type="text" name="username" required class="required:border-red-500">
placeholder-shown استفاده کنید.<input type="text" name="username" required placeholder="Enter your username" class="placeholder-shown:text-gray-400">
autofill استفاده کنید.HTML
<input type="email" name="email" required class="autofill:text-green-500">
read-only استفاده کنید.HTML
<input type="text" name="username" readonly class="read-only:bg-gray-200">
active استفاده کنید.HTML
<button type="submit" class="active:bg-blue-600">Submit</button>
visited استفاده کنید.HTML
<a href="https://example.com" class="visited:text-purple-500">Link</a>
target استفاده کنید.HTML
<a href="https://example.com" target="_blank" class="target:text-blue-600">Link</a>
checked استفاده کنید.HTML
<input type="checkbox" name="terms" class="checked:bg-green-500">
indeterminate استفاده کنید.HTML
<input type="checkbox" name="terms" class="indeterminate:bg-yellow-500">
default استفاده کنید.HTML
<input type="radio" name="size" value="small" checked class="default:bg-blue-500">
با استفاده از این کلاسها، میتوانید به راحتی ظاهر فرم خود را بر اساس وضعیتهای مختلف آن سفارشیسازی کنید. این باعث میشود فرم شما تعاملیتر و کاربرپسندتر شود.