HTML Div Element

<div> तत्व का उपयोग अन्य HTML तत्वों के लिए एक कंटेनर के रूप में किया जाता है

The <div> Element

<div> तत्व डिफ़ॉल्ट रूप से एक ब्लॉक तत्व है, जिसका अर्थ है कि यह सभी उपलब्ध चौड़ाई लेता है, और अग्रणी और अनुगामी लाइन ब्रेक के साथ आता है।

Example

एक <div> तत्व सभी उपलब्ध चौड़ाई लेता है:

HTML Code:

Lorem Ipsum <div>I am a div</div> dolor sit amet.
Result:
Lorem Ipsum
I am a div
dolor sit amet.

<div> तत्व में कोई आवश्यक विशेषताएँ नहीं हैं, लेकिन शैली, वर्ग और आईडी सामान्य हैं।

<div> as a container

<div> तत्व का उपयोग अक्सर वेब पेज के हिस्सों को एक साथ समूहित करने के लिए किया जाता है।

Example

HTML तत्वों वाला एक <div> तत्व:

HTML Code:

<div>
  <h2>London</h2>
  <p>London is the capital city of England.</p>
  <p>London has over 9 million inhabitants.</p>
</div>
Result:

London

London is the capital city of England.

London has over 9 million inhabitants.

Center align a <div> element

यदि आपके पास एक <div> तत्व है जो 100% चौड़ा नहीं है और आप चाहते हैं कि यह केंद्र-संरेखित हो, तो CSS मार्जिन विशेषता को ऑटो पर सेट करें।

Example

CSS and HTML Code:

<style>
div {
  width:300px;
  margin:auto;
}
</style>

<div>
  <h2>London</h2>
  <p>London is the capital city of England.</p>
  <p>London has over 9 million inhabitants.</p>
</div>
Result:

London

London is the capital city of England.

London has over 9 million inhabitants.

Multiple <div> elements

एक एकल पृष्ठ में एकाधिक <div> कंटेनर हो सकते हैं।

Example

HTML Code:

<div>
  <h2>London</h2>
  <p>London is the capital city of England.</p>
  <p>London has over 9 million inhabitants.</p>
</div>

<div>
  <h2>Oslo</h2>
  <p>Oslo is the capital city of Norway.</p>
  <p>Oslo has over 700,000 inhabitants.</p>
</div>

<div>
  <h2>Rome</h2>
  <p>Rome is the capital city of Italy.</p>
  <p>Rome has over 4 million inhabitants.</p>
</div>
Result:

London

London is the capital city of England.

London has over 9 million inhabitants.

Oslo

Oslo is the capital city of Norway.

Oslo has over 700,000 inhabitants.

Rome

Rome is the capital city of Italy.

Rome has over 4 million inhabitants.

Aligning <div> elements side by side

वेब पेज बनाते समय, आप अक्सर दो या दो से अधिक <div> तत्वों को इस तरह एक साथ रखना चाहेंगे:

London

London is the capital city of England.

London has over 9 million inhabitants.

Oslo

Oslo is the capital city of Norway.

Oslo has over 700,000 inhabitants.

Rome

Rome is the capital city of Italy.

Rome has over 4 million inhabitants.

तत्वों को पार्श्व रूप से संरेखित करने के विभिन्न तरीके हैं, सभी में कुछ सीएसएस स्टाइल शामिल हैं। हम सबसे सामान्य तरीकों पर गौर करेंगे:

Method Description Example Code
Float CSS फ्लोट विशेषता मूल रूप से <div> तत्वों को पार्श्व रूप से संरेखित करने के लिए नहीं बनाई गई थी, लेकिन इस उद्देश्य के लिए वर्षों से इसका उपयोग किया जाता रहा है।
.mycontainer div {
  width:33%;
  float:left;
}
Inline-block यदि आप <div> तत्व में डिस्प्ले विशेषता को ब्लॉक से इनलाइन-ब्लॉक में बदलते हैं, तो <div> तत्व पहले और बाद में लाइन स्पेसिंग नहीं जोड़ेंगे, और एक दूसरे के शीर्ष के बजाय किनारे पर प्रदर्शित होंगे।
div {
  width: 30%;
  display: inline-block;
}
Flex सीएसएस फ्लेक्सबॉक्स लेआउट मॉड्यूल को फ्लोटिंग या पोजिशनिंग का उपयोग किए बिना लचीले उत्तरदायी लेआउट को डिजाइन करना आसान बनाने के लिए पेश किया गया था।
.mycontainer {
  display: flex;
}
.mycontainer > div {
  width:33%;
}
Grid सीएसएस ग्रिड लेआउट मॉड्यूल पंक्तियों और स्तंभों के साथ एक ग्रिड-आधारित लेआउट प्रदान करता है, जिससे फ्लोटिंग और पोजिशनिंग का उपयोग किए बिना वेब पेज डिजाइन करना आसान हो जाता है।
.grid-container {
  display: grid;
  grid-template-columns: 33% 33% 33%;
}

सहायता नोट:

फ्लोट, फ्लेक्स और ग्रिड के बारे में अधिक जानने के लिए हमारे सीएसएस ट्यूटोरियल पर जाएँ। जैसिफ टीम इन सभी तरीकों को विस्तृत उदाहरणों के साथ प्रदान करती है।

Exercise

निम्नलिखित कोड पर विचार करें:

<div style='width:200px;margin:auto'>
  <h2>London</h2>
</div>
Result Preview:

London

DIV तत्व को कैसे संरेखित किया जाएगा?

Left aligned
✗ ग़लत! मार्जिन:ऑटो के साथ संरेखित नहीं छोड़ा जाएगा
Center aligned
✓ ठीक है! मार्जिन: ऑटो एक DIV तत्व को केंद्र-संरेखित करता है
Right aligned
✗ ग़लत! मार्जिन-बाएं: दाएं संरेखण के लिए ऑटो; मार्जिन-दाएं: 0; आवश्यक

HTML Tags

Tag Description
<div> किसी दस्तावेज़ (अनुभाग-स्तर) में एक अनुभाग को परिभाषित करता है।

नोट:

सभी उपलब्ध HTML टैग्स की पूरी सूची के लिए, हमारे HTML टैग संदर्भ पर जाएँ।