📅 Week 3 - Day 2: Styling Forms & Buttons

Wednesday | Duration: 3 hours

🎯 Learning Objectives

  • Apply consistent styling using classes and IDs
  • Style form elements beautifully
  • Create interactive buttons with hover effects
  • Add CSS transitions and animations
  • Style the Student Registration Form

🎨 Styling Form Elements

Input Fields

/* Basic input styling */ input[type="text"], input[type="email"], input[type="password"], input[type="tel"], input[type="date"], textarea, select { width: 100%; padding: 12px; border: 2px solid #ddd; border-radius: 5px; font-size: 16px; font-family: inherit; transition: border-color 0.3s; } /* Focus state */ input:focus, textarea:focus, select:focus { outline: none; border-color: #10b981; box-shadow: 0 0 5px rgba(16, 185, 129, 0.3); } /* Placeholder styling */ input::placeholder, textarea::placeholder { color: #999; font-style: italic; }

Live Example - Styled Input:

Click inside the input to see the focus effect:

Notice: The border turns green and gets a subtle shadow when focused.

Labels

label { display: block; margin-bottom: 8px; font-weight: bold; color: #333; } /* Required indicator */ label.required::after { content: " *"; color: red; }

Live Example - Label with Required Indicator:

Radio Buttons & Checkboxes

/* Container for radio/checkbox */ .radio-group, .checkbox-group { margin: 15px 0; } /* Style labels for radio/checkbox */ .radio-group label, .checkbox-group label { display: inline-block; margin-right: 20px; font-weight: normal; cursor: pointer; } /* Make inputs larger */ input[type="radio"], input[type="checkbox"] { width: 18px; height: 18px; margin-right: 5px; cursor: pointer; }

Live Example - Radio Buttons & Checkboxes:

Select Dropdowns

select { appearance: none; /* Remove default arrow */ background-image: url("data:image/svg+xml;utf8,"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 40px; cursor: pointer; }

Live Example - Styled Dropdown:

Textarea

textarea { resize: vertical; /* Allow vertical resize only */ min-height: 120px; font-family: inherit; }

Live Example - Styled Textarea:

Notice: You can only resize vertically (drag the bottom-right corner).

🔘 Styling Buttons

Basic Button Styles

button, input[type="submit"], input[type="button"], .btn { padding: 12px 30px; font-size: 16px; font-weight: bold; border: none; border-radius: 5px; cursor: pointer; transition: all 0.3s ease; display: inline-block; text-align: center; text-decoration: none; } /* Primary button */ .btn-primary { background: #10b981; color: white; } .btn-primary:hover { background: #34d399; transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.2); } /* Secondary button */ .btn-secondary { background: #757575; color: white; } .btn-secondary:hover { background: #616161; } /* Success button */ .btn-success { background: #4caf50; color: white; } /* Danger button */ .btn-danger { background: #f44336; color: white; } /* Outline button */ .btn-outline { background: transparent; color: #10b981; border: 2px solid #10b981; } .btn-outline:hover { background: #10b981; color: white; }

Live Example - Interactive Buttons:

Hover over each button to see the effects:

Button Sizes

.btn-small { padding: 8px 20px; font-size: 14px; } .btn-large { padding: 15px 40px; font-size: 18px; } .btn-block { display: block; width: 100%; }

Live Example - Button Sizes:

✨ CSS Transitions

Transitions create smooth changes between CSS property values.

/* Basic transition */ .element { transition: property duration timing-function delay; } /* Examples */ button { background: #10b981; transition: background 0.3s ease; } button:hover { background: #34d399; } /* Multiple properties */ .card { transform: scale(1); box-shadow: 0 2px 5px rgba(0,0,0,0.1); transition: transform 0.3s, box-shadow 0.3s; } .card:hover { transform: scale(1.05); box-shadow: 0 5px 15px rgba(0,0,0,0.3); } /* All properties */ .link { transition: all 0.3s ease; }

Live Example - Smooth Transition:

Hover over the card to see scale and shadow transition:

Hover Me!

This card scales up and shadow intensifies smoothly on hover.

Timing Functions

  • ease: Slow start, fast, then slow end (default)
  • linear: Same speed from start to end
  • ease-in: Slow start
  • ease-out: Slow end
  • ease-in-out: Slow start and end

🎬 Hover Effects

/* Scale effect */ .card { transition: transform 0.3s; } .card:hover { transform: scale(1.1); } /* Slide up */ .element { transition: transform 0.3s; } .element:hover { transform: translateY(-10px); } /* Color change */ .link { color: #333; transition: color 0.3s; } .link:hover { color: #10b981; } /* Background gradient shift */ .button { background: linear-gradient(to right, #10b981, #34d399); background-size: 200% 100%; transition: background-position 0.3s; } .button:hover { background-position: 100% 0; } /* Box shadow */ .card { box-shadow: 0 2px 5px rgba(0,0,0,0.1); transition: box-shadow 0.3s; } .card:hover { box-shadow: 0 8px 20px rgba(0,0,0,0.3); }

Live Example - Various Hover Effects:

Scale Effect
Slide Up
Shadow Grow

Hover over each box to see different transition effects!

💻 Main Activity: Style Registration Form

Task: Beautify the Student Registration Form

Create styled-form.css and apply it to registration.html

Complete Form CSS

/* styled-form.css */ * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Segoe UI', Arial, sans-serif; background: linear-gradient(135deg, #10b981 0%, #34d399 100%); padding: 20px; min-height: 100vh; } .form-container { max-width: 700px; margin: 0 auto; background: white; padding: 40px; border-radius: 15px; box-shadow: 0 10px 40px rgba(0,0,0,0.2); } h1 { color: #10b981; text-align: center; margin-bottom: 10px; font-size: 2.5em; } .subtitle { text-align: center; color: #666; margin-bottom: 30px; } /* Section headers */ h2 { color: #333; margin-top: 30px; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 2px solid #10b981; } /* Form groups */ .form-group { margin-bottom: 25px; } /* Labels */ label { display: block; margin-bottom: 8px; font-weight: 600; color: #333; } label.required::after { content: " *"; color: #f44336; } /* Input fields */ input[type="text"], input[type="email"], input[type="tel"], input[type="date"], select, textarea { width: 100%; padding: 12px 15px; border: 2px solid #ddd; border-radius: 8px; font-size: 16px; font-family: inherit; transition: all 0.3s; } input:focus, select:focus, textarea:focus { outline: none; border-color: #10b981; box-shadow: 0 0 8px rgba(16, 185, 129, 0.3); } /* Placeholder */ input::placeholder, textarea::placeholder { color: #999; } /* Select dropdown */ select { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml;utf8,"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 40px; } /* Textarea */ textarea { resize: vertical; min-height: 120px; } /* Radio and checkbox groups */ .radio-group, .checkbox-group { margin: 15px 0; } .radio-group label, .checkbox-group label { display: inline-flex; align-items: center; margin-right: 25px; margin-bottom: 10px; font-weight: normal; cursor: pointer; } input[type="radio"], input[type="checkbox"] { width: 20px; height: 20px; margin-right: 8px; cursor: pointer; accent-color: #10b981; } /* Buttons container */ .button-group { display: flex; gap: 15px; margin-top: 30px; } /* Buttons */ button, input[type="submit"], input[type="reset"] { flex: 1; padding: 15px 30px; font-size: 16px; font-weight: bold; border: none; border-radius: 8px; cursor: pointer; transition: all 0.3s ease; } button[type="submit"], input[type="submit"] { background: linear-gradient(135deg, #10b981 0%, #34d399 100%); color: white; } button[type="submit"]:hover { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(16, 185, 129, 0.4); } button[type="reset"], input[type="reset"] { background: #757575; color: white; } button[type="reset"]:hover { background: #616161; } /* Agreement checkbox */ .agreement { margin: 25px 0; padding: 15px; background: #f9f9f9; border-radius: 8px; } .agreement label { display: flex; align-items: center; font-weight: normal; } .agreement input[type="checkbox"] { margin-right: 10px; } /* Error state */ input:invalid:not(:placeholder-shown) { border-color: #f44336; } /* Success state */ input:valid:not(:placeholder-shown) { border-color: #4caf50; } /* Responsive */ @media (max-width: 768px) { .form-container { padding: 30px 20px; } h1 { font-size: 2em; } .button-group { flex-direction: column; } .radio-group label, .checkbox-group label { display: flex; width: 100%; } }

✏️ Practice Exercises

Exercise 1: Contact Form

Create a beautiful contact form with:

  • Name, email, subject, message fields
  • Custom styled inputs with focus effects
  • Animated submit button
  • Responsive design

Exercise 2: Button Collection

Create a page showcasing different button styles:

  • Primary, secondary, success, danger, warning
  • Different sizes (small, medium, large)
  • Outline buttons
  • Icon buttons
  • Loading buttons

Exercise 3: Hover Effects Gallery

Create cards with different hover effects:

  • Scale transform
  • Rotate effect
  • Color overlay
  • Shadow increase
  • Slide up content

✅ Today's Deliverable

  • styled-form.css with comprehensive form styling
  • Updated registration.html with beautiful styling
  • Interactive buttons with hover effects
  • Smooth transitions on all interactive elements
  • Screenshots of form on desktop and mobile
  • Committed to GitHub: "Add form styling and transitions"