Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Creating Forms | Building Basic Components
Tailwind CSS for Web Development

book
Challenge: Creating Forms

Task

Use Tailwind CSS to complete the styling of a form with inputs, textareas, radio buttons, and a switch.

Fill in the blanks with the appropriate Tailwind CSS classes to achieve the desired styling.

  • Inputs and Textareas:
    • Light gray border (border-gray-300);
    • Medium rounded corners (rounded-md);
    • Focus state with a blue ring (focus:ring-2 and focus:ring-blue-500).
  • Submit Button:
    • Primary blue background (bg-blue-500);
    • Darker blue on hover (hover:bg-blue-700);
    • Rounded corners (rounded);
    • Focus state with a ring (focus:outline-none, focus:ring-2, and focus:ring-blue-500).
html

index.html

copy
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Challenge: Forms - Task</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 p-8">
<div class="max-w-md mx-auto mt-10 p-6 bg-white shadow-md rounded-lg">
<form>
<!-- Text Input -->
<div class="mb-4">
<label
class="block text-gray-700 text-sm font-bold mb-2"
for="username"
>
Username
</label>
<input
class="shadow appearance-none border _____ _____ p-2 w-full focus:_____ focus:_____"
id="username"
type="text"
placeholder="Enter your username"
/>
</div>
<!-- Textarea -->
<div class="mb-4">
<label
class="block text-gray-700 text-sm font-bold mb-2"
for="message"
>
Message
</label>
<textarea
class="shadow appearance-none border _____ _____ p-2 w-full focus:_____ focus:_____"
  1. Border Color: Use border-gray-300 for a light gray border;
  2. Rounded Corners: Use rounded-md for medium rounded corners;
  3. Focus Ring: Use focus:ring-2 for adding a ring on focus and focus:ring-blue-500 for blue color.
  4. Submit Button Hover: Use hover:bg-blue-700 for a darker blue on hover;
  5. Submit Button Ring: Use focus:outline-none to remove default focus outline, focus:ring-2 to add a ring on focus, and focus:ring-blue-500 to set the ring color.
html

index.html

copy
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Challenge: Forms - Solution</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 p-8">
<div class="max-w-md mx-auto mt-10 p-6 bg-white shadow-md rounded-lg">
<form>
<!-- Text Input -->
<div class="mb-4">
<label
class="block text-gray-700 text-sm font-bold mb-2"
for="username"
>
Username
</label>
<input
class="shadow appearance-none border border-gray-300 rounded-md p-2 w-full focus:ring-2 focus:ring-blue-500"
id="username"
type="text"
placeholder="Enter your username"
/>
</div>
<!-- Textarea -->
<div class="mb-4">
<label
class="block text-gray-700 text-sm font-bold mb-2"
for="message"
>
Message
</label>
<textarea
class="shadow appearance-none border border-gray-300 rounded-md p-2 w-full focus:ring-2 focus:ring-blue-500"
id="message"
rows="4"
placeholder="Enter your message"
></textarea>
</div>
<!-- Radio Buttons -->
<div class="mb-4">
<span class="text-gray-700">Gender</span>
<div class="mt-2">
<label class="inline-flex items-center">
<input
type="radio"
class="form-radio text-blue-500"
name="gender"
value="male"
/>
<span class="ml-2">Male</span>
</label>
<label class="inline-flex items-center ml-6">
<input
type="radio"
class="form-radio text-blue-500"
name="gender"
value="female"
/>
<span class="ml-2">Female</span>
</label>
</div>
</div>
<!-- Switch -->
<div class="mb-4">
<label class="flex items-center">
<span class="mr-2 text-gray-700">Enable notifications</span>
<input
type="checkbox"
class="form-checkbox h-6 w-6 text-green-500"
/>
</label>
</div>
<!-- Submit Button -->
<div class="mb-4">
<button
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:ring-2 focus:ring-blue-500"
>
Submit
</button>
</div>
</form>
</div>
</body>
</html>

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 6
We use cookies to make your experience better!
some-alt