Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> CSS

CSS counter-increment प्रॉपर्टी से काउंटर मान बढ़ाएं

CSS counter-increment प्रॉपर्टी का उपयोग करके CSS काउंटर के मान को बढ़ाया (increment) जाता है। यह आमतौर पर ::before या ::after स्यूडो-एलिमेंट के साथ counter-reset प्रॉपर्टी के संयोजन में उपयोग किया जाता है।

उदाहरण

नीचे दिए गए उदाहरण में, प्रत्येक <h2> तत्व के लिए काउंटर बढ़ाया जाता है और उसके सामने नंबर प्रदर्शित किया जाता है।

<!DOCTYPE html>
<html>
<head>
  <style>
    body {
      counter-reset: section;
    }
    h2::before {
      counter-increment: section;
      content: "Fruit " counter(section) " - ";
    }
  </style>
</head>
<body>
  <h1>Fruits</h1>
  <h2>Mango</h2>
  <h2>Kiwi</h2>
</body>
</html>

कैसे काम करता है:

  1. counter-reset: section - पैरेंट (body) पर काउंटर "section" को 0 पर रीसेट करता है
  2. counter-increment: section - प्रत्येक h2 के लिए काउंटर को 1 से बढ़ाता है
  3. content: "Fruit " counter(section) " - " - काउंटर मान को कंटेंट में सम्मिलित करता है

उन्नत उपयोग: counter-increment: section 2 से 2 से बढ़ा सकते हैं, counter-increment: section -1 से घटा सकते हैं।

  1. - CSS white-space प्रॉपर्टी

    white-space प्रॉपर्टी का उपयोग किसी तत्व के अंदर व्हाइट स्पेस (स्पेस, टैब, लाइन ब्रेक) को कैसे संभाला जाए, इसे नियंत्रित करने के लिए किया जाता है। उदाहरण <!DOCTYPE html> <html> <head> <style> p.demo1 { white-space: normal; } p.demo2 {

  1. CSS में writing-mode प्रॉपर्टी CSS में writing-mode प्रॉपर्टी

    writing-mode प्रॉपर्टी का उपयोग यह सेट करने के लिए किया जाता है कि टेक्स्ट की लाइनें क्षैतिज या लंबवत रूप से रखी गई हैं। प्रॉपर्टी मान writing-mode: horizontal-tb | vertical-rl | vertical-lr; उदाहरण <!DOCTYPE html> <html> <head> <style> p { writing-mode: vertic

  1. CSS scroll-behavior प्रॉपर्टी CSS scroll-behavior प्रॉपर्टी

    scroll-behavior प्रॉपर्टी scroll-behavior प्रॉपर्टी का उपयोग स्क्रॉल के व्यवहार को सेट करने के लिए किया जाता है। हम निम्नलिखित मान सेट कर सकते हैं: scroll-behavior: auto | smooth | initial | inherit; मान: auto: तुरंत जंप (डिफ़ॉल्ट) smooth: स्मूथ एनिमेटेड स्क्रॉल initial: डिफ़ॉल्ट मान पर रीस