HTML डिव
In this page:
<div class="classname">
Content
</div>
Generic div Container
div tag एक generic block-level division या container define करता है। इसका कोई semantic अर्थ नहीं होता, लेकिन elements को group करने, sections को अलग करने, और CSS layout rules लागू करने के लिए यह बेहद उपयोगी है।
उदाहरण: The Generic div Container
<div>Grouped content with no semantic meaning</div>
CSS से Divisions को Style करना
चूंकि div एक generic block container है, इसलिए यह आपके page पर custom visual cards, boxes, borders, और margins बनाने के लिए CSS classes लगाने के लिए एकदम सही element है।
उदाहरण: Styling Divisions with CSS
<div class="card">Styled card content</div>
Flexbox से Flexible Column Grids
आप modern, flexible column grids बनाने के लिए div tags इस्तेमाल कर सकते हैं। किसी parent div की display property को flex पर सेट करके, आप उसकी child divs को साफ-सुथरे तरीके से side-by-side arrange कर सकते हैं और उनका alignment control कर सकते हैं।
उदाहरण: Flexible Column Grids with Flexbox
<div style="display: flex;">
<div>Column 1</div>
<div>Column 2</div>
</div>
Consistent Indentation और Nesting
कई divs को एक-दूसरे के अंदर nest करना complex web pages बनाने की चाबी है। अपना कोड साफ रखने के लिए, हमेशा clear indentation इस्तेमाल करें ताकि दिखे कि कौन-सी divs किन divs के अंदर nested हैं।
उदाहरण: Consistent Indentation and Nesting
<div class="outer">
<div class="inner">
Nested content
</div>
</div>
Div Accessibility और ARIA
चूंकि div एक पूरी तरह generic, non-semantic element है, इसलिए screen readers जैसे assistive devices इसे पूरी तरह अनदेखा कर देते हैं।
अगर आप किसी interactive component (जैसे custom button या modal) बनाने के लिए div इस्तेमाल करते हैं, तो उसे accessible रखने के लिए आपको standard ARIA roles जोड़ने होंगे।
उदाहरण: Div Accessibility and ARIA
<div role="button" tabindex="0" aria-label="Close dialog">X</div>
- semantic layout tags के बजाय हर चीज़ के लिए plain, generic div elements इस्तेमाल करना।
- closing div tag लिखना भूल जाना, जिससे बाद के elements merge हो जाते हैं और layouts टूट जाते हैं।
- ज़रूरी ARIA roles या keyboard focus support जोड़े बिना styled div containers को interactive buttons की तरह इस्तेमाल करना।
- div tag एक generic block-level container define करता है जिसमें कोई semantic meaning नहीं होती।
- elements को group करने, sections अलग करने, और CSS styling या Flexbox layouts साफ तरीके से लागू करने के लिए divs इस्तेमाल करें।
- अपने layouts को organized और maintain करने में आसान रखने के लिए हमेशा साफ indentation और closing tags लिखें।
standard div elements और block-level styling rules सभी web browsers में natively supported हैं।
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: