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

CSS का उपयोग करके ओवरफ्लोइंग कंटेंट को संभालना

हम किसी एलिमेंट के ओवरफ्लोइंग कंटेंट को मैनेज/हैंडल करने के लिए CSS overflow प्रॉपर्टी का उपयोग कर सकते हैं। यह प्रॉपर्टी यूजर को कंटेंट क्लिप करने, क्लिप्ड कंटेंट देखने के लिए स्क्रॉलबार प्रदान करने, कंटेंट को कंटेनर के बाहर रेंडर करने की अनुमति देती है, इसीलिए इसका नाम overflow है।

सिंटैक्स

CSS Overflow प्रॉपर्टी के लिए सिंटैक्स निम्नानुसार है:

Selector {    overflow: /*value*/ }

आइए CSS overflow प्रॉपर्टी का एक उदाहरण देखते हैं:

उदाहरण

<!DOCTYPE html> <html> <head> <title>CSS Overflow</title> <style> form {    width:70%;    margin: 0 auto;    text-align: center; } * {    padding: 2px;    margin:5px; } input[type="button"] {    border-radius: 10px; } #containerDiv {    margin: 0 auto;    height: 110px;    overflow: scroll; } </style></head> <body> <form> <fieldset> <legend>CSS Overflow</legend> <div id="containerDiv"> This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text.</div> <input type="button" onclick="add()" value="Remove Scrollbars"> </fieldset> </form> <script> function add() {    document.querySelector('#containerDiv').style.overflow = "hidden"; } </script> </body> </html>

आउटपुट

'Remove Scrollbars' बटन पर क्लिक करने से पहले:

CSS का उपयोग करके ओवरफ्लोइंग कंटेंट को संभालना

'Remove Scrollbars' बटन पर क्लिक करने के बाद:

CSS का उपयोग करके ओवरफ्लोइंग कंटेंट को संभालना

आइए CSS overflow प्रॉपर्टी का एक और उदाहरण देखते हैं:

दूसरा उदाहरण

<!DOCTYPE html> <html> <head> <title>CSS Overflow</title> <style> form {    width:70%;    margin: 0 auto;    text-align: center; } * {    padding: 2px;    margin:5px; } input[type="button"] {    border-radius: 10px; } #containerDiv {    margin: 0 auto;    height: 100px;    width: 100px;    overflow: auto; } </style> </head> <body> <form> <fieldset> <legend>CSS Overflow</legend> <div id="containerDiv"> <img id="image" src="https://www.tutorialspoint.com/sas/images/sas-mini-logo.jpg"> </div>   <input type="button" onclick="fitHeight()" value="Remove Scrollbars"> </fieldset> </form> <script> var divDisplay = document.getElementById("divDisplay"); var imgSelect = document.getElementById("image"); var containerDiv = document.getElementById("containerDiv"); function fitHeight() {    containerDiv.style.height = imgSelect.height+'px';    containerDiv.style.width = imgSelect.width+'px';    containerDiv.style.overflow = 'hidden'; } </script> </body> </html>

आउटपुट

किसी बटन पर क्लिक करने से पहले:

CSS का उपयोग करके ओवरफ्लोइंग कंटेंट को संभालना

'Remove Scrollbars' बटन पर क्लिक करने के बाद:

CSS का उपयोग करके ओवरफ्लोइंग कंटेंट को संभालना

  1. CSS में Display None का उपयोग CSS में Display None का उपयोग

    CSS Display None डेवलपर को उस एलिमेंट को छुपाने में मदद करता है जिसकी display प्रॉपर्टी none पर सेट है। जिस एलिमेंट का display none पर सेट है, उसके लिए कोई बॉक्स जनरेट नहीं होता और यहां तक कि उसके चाइल्ड एलिमेंट्स के लिए भी नहीं जिनका display none के अलावा अन्य मानों पर सेट हो सकता है। सिंटैक्स CSS

  1. CSS में RGBA से ट्रांसपेरेंसी (पारदर्शिता) कैसे बनाएं? CSS में RGBA से ट्रांसपेरेंसी (पारदर्शिता) कैसे बनाएं?

    RGBA कलर फॉर्मेट में अल्फा चैनल (0 से 1) पारदर्शिता नियंत्रित करता है। rgba(0, 0, 255, 0.582) में 0.582 ओपेसिटी है। यह केवल बैकग्राउंड को पारदर्शी बनाता है, कंटेंट को नहीं। उदाहरण <!DOCTYPE html> <html> <head> <style> body { font-family: Segoe UI, Tahoma, Geneva, Verd

  1. CSS में डेटा-एट्रिब्यूट्स (data-*) का उपयोग करना CSS में डेटा-एट्रिब्यूट्स (data-*) का उपयोग करना

    परिचय हम data-* एट्रिब्यूट्स का उपयोग करके एलिमेंट्स के बारे में अतिरिक्त जानकारी संग्रहीत कर सकते हैं। ये कस्टम डेटा एट्रिब्यूट्स CSS सेलेक्टर्स (attr() फंक्शन के साथ) और जावास्क्रिप्ट दोनों के लिए सुलभ हैं। उदाहरण 1: जावास्क्रिप्ट इंटरैक्शन के लिए डेटा एट्रिब्यूट्स <!DOCTYPE html> <html