CSS Forms
In this page:
input, select, textarea {
width: 100%;
padding: length;
border: width style color;
}
input:focus {
outline: none;
}
Text Input Boxes को Style करना
Default रूप से, browsers form inputs को rigid, outdated borders के साथ render करते हैं। आप इन inputs को CSS properties इस्तेमाल करके आसानी से customize कर सकते हैं ताकि उनकी borders, inner padding, background colors, और typography styles adjust हो सकें।
उदाहरण: Styling Text Input Boxes
<style>
input[type="text"] {
border: 1px solid #ccc;
padding: 8px;
font-family: sans-serif;
}
</style>
<input type="text" placeholder="Your name">
Accessible Active Focus Indicators
जब users आपके form में tab करते हैं या किसी input को click करते हैं, तो element एक 'active focus' state में चला जाता है। आप :focus pseudo-class इस्तेमाल करके इस state की styling customize कर सकते हैं ताकि active inputs साफ़ तरीके से उभरें।
उदाहरण: Accessible Active Focus Indicators
<style>
input:focus {
border-color: blue;
box-shadow: 0 0 4px blue;
}
</style>
<input type="text">
Checkbox और Radio Alignments
Default रूप से, browsers checkboxes और radio buttons को उनके text labels से थोड़ा misaligned render करते हैं। आप उन्हें perfectly align करने के लिए उनके parent wrappers पर Flexbox alignment properties इस्तेमाल कर सकते हैं।
उदाहरण: Checkbox and Radio Alignments
<style>
label {
display: flex;
align-items: center;
gap: 6px;
}
</style>
<label><input type="checkbox"> Subscribe</label>
select Dropdown Boxes को Customize करना
Native select dropdown menus अलग-अलग devices में blocky और inconsistent दिख सकते हैं। आप browser default designs हटाने के लिए CSS properties (जैसे appearance: none) इस्तेमाल करके उन्हें customize कर सकते हैं, अपनी खुद की custom borders, padding, और arrow icons जोड़ते हुए।
उदाहरण: Customizing select Dropdown Boxes
<style>
select {
appearance: none;
border: 1px solid #ccc;
padding: 8px;
}
</style>
<select><option>Choice A</option></select>
Form Action Submit Buttons को Style करना
form submit button आपके page पर final call-to-action है। इसे high-contrast colors, custom borders, और smooth hover animations से style करके, आप data submit करना intuitive और visually engaging बना सकते हैं।
उदाहरण: Styling Form Action Submit Buttons
<style>
button[type="submit"] {
background: royalblue;
color: white;
border: none;
padding: 10px 20px;
}
button[type="submit"]:active {
background: darkblue;
}
</style>
<button type="submit">Submit</button>
- form inputs पर box-sizing: border-box set करना भूल जाना, जिससे full-width inputs overflow हो जाते हैं।
- browser focus outlines को CSS (outline: none) से पूरी तरह hide करना बिना उन्हें custom focus styles से replace किए।
- buttons design करने के लिए non-semantic divs इस्तेमाल करना, keyboard focus और tab navigation तोड़ते हुए।
- text inputs को custom padding, borders, और rounded corners से style करें, और हमेशा box-sizing: border-box इस्तेमाल करें।
- user experience बेहतर करने के लिए :focus pseudo-class इस्तेमाल करके active input fields को highlight करें।
- Flexbox इस्तेमाल करके checkboxes और labels को perfectly align करें, और submit buttons को high-contrast hover transitions से style करें।
Standard form styling properties और basic focus indicators हर modern web browser द्वारा natively supported हैं।
Chapter Quiz — Complete all 22 topics to unlock
0/22 topics done
Complete these topics first:
- CSS Combinators
- CSS Pseudo-classes
- CSS Pseudo-elements
- CSS Opacity
- CSS Navigation Bar
- CSS Vertical Navbar
- CSS Horizontal Navbar
- CSS Dropdowns
- CSS Advanced Dropdowns
- CSS Image Gallery
- CSS Image Sprites
- CSS Attribute Selectors
- CSS Forms
- CSS Counters
- CSS Specificity
- CSS Specificity Hierarchy
- CSS Variables
- CSS !important
- CSS Box Sizing
- CSS Media Queries
- CSS Pointer Events
- CSS Outline