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

CSS में स्क्रॉल पर फिक्स्ड हेडर के साथ HTML टेबल

position: sticky और top: 0 सेट करके, हम HTML टेबल में स्क्रॉल पर एक फिक्स्ड हेडर बना सकते हैं।

उदाहरण 1

निम्न उदाहरण हमें इसका कार्यान्वयन करने का अंदाजा देते हैं:

<!DOCTYPE html> <html> <head> <style> div {    color: white;    display: flex;    padding: 2%;    background-color: rgba(190,155,150);    height: 135px;    overflow-y: scroll; } td,th,p {    text-align: center;    font-size: 1.25em; } table {    padding: 3%;    border-collapse: collapse;    border: 2px ridge green; } th {    top: 0;    position: sticky;    background: #e5d2f1;    color: black; } </style> </head> <body> <div> <table> <thead> <tr> <th>A </th> <th>B </th> <th>C </th> <th>D </th> <th>E </th> </tr> </thead> <tr> <td>Hey</td> <td>Hey</td> <td>Hey</td> <td>Hey</td> <td>Hey</td> </tr> <tr> <td>Demo</td> <td>Demo</td> <td>Demo</td> <td>Demo</td> <td>Demo</td> </tr> <tr> <td>Yo</td> <td>Yo</td> <td>Yo</td> <td>Yo</td> <td>Yo</td> </tr> <tr> <td>Demo</td> <td>Demo</td> <td>Demo</td> <td>Demo</td> <td>Demo</td> </tr> </table> <p> Duis tincidunt fermentum ipsum vel sagittis. Sed ultrices quis dui ut rutrum. Quisque et varius tellus, ut vestibulum purus. Etiam in erat fringilla, laoreet libero eu, facilisis ante. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Duis eu ornare augue, ut facilisis odio. </p> </div> </body> </html>

आउटपुट

यह निम्न परिणाम उत्पन्न करेगा:

CSS में स्क्रॉल पर फिक्स्ड हेडर के साथ HTML टेबल

उदाहरण 2

<!DOCTYPE html> <html> <head> <style> div {    padding: 2%;    height: 40px;    overflow-y: scroll;    box-shadow: inset 0 0 12px lightgreen; } tr th {    background: #25f2f1; } table {    text-align: center;    position: relative;    border-collapse: separated;    width: 100%; } th {    top: 0;    position: sticky;    background: white; } </style> </head> <body> <div> <table> <thead> <tr> <th>A </th> <th>B </th> <th>C </th> <th>D </th> <th>E </th> </tr> </thead> <tr> <td>Hey</td> <td>Hey</td> <td>Hey</td> <td>Hey</td> <td>Hey</td> </tr> <tr> <td>Demo</td> <td>Demo</td> <td>Demo</td> <td>Demo</td> <td>Demo</td> </tr> <tr> <td>Yo</td> <td>Yo</td> <td>Yo</td> <td>Yo</td> <td>Yo</td> </tr> <tr> <td>Demo</td> <td>Demo</td> <td>Demo</td> <td>Demo</td> <td>Demo</td> </tr> </table> </div> </body> </html>

आउटपुट

यह निम्न परिणाम उत्पन्न करेगा:

CSS में स्क्रॉल पर फिक्स्ड हेडर के साथ HTML टेबल

  1. CSS से रिस्पॉन्सिव टेबल कैसे बनाएं? CSS से रिस्पॉन्सिव टेबल कैसे बनाएं?

    रिस्पॉन्सिव टेबल के लिए टेबल को overflow-x: auto वाले डिव में लपेटें। छोटे स्क्रीन पर क्षैतिज स्क्रॉलबार दिखाई देगा, टेबल संरचना बनी रहती है। ज़ेबरा स्ट्रिपिंग शामिल है। उदाहरण <!DOCTYPE html> <html> <head> <meta name=viewport content=width=device-width, initial-scale=1>

  1. CSS और JavaScript से स्क्रॉल पर हेडर सिकोड़ें कैसे करें? CSS और JavaScript से स्क्रॉल पर हेडर सिकोड़ें कैसे करें?

    CSS और JavaScript से स्क्रॉल पर हेडर सिकोड़ने के लिए, कोड निम्नानुसार है -उदाहरण<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1" /> <style>    body {       font-family: "S

  1. CSS के साथ ऑन-स्क्रॉल फिक्स्ड नेविगेशन बार कैसे बनाएं CSS के साथ ऑन-स्क्रॉल फिक्स्ड नेविगेशन बार कैसे बनाएं

    परिचय CSS position प्रॉपर्टी को निर्दिष्ट करके, हम CSS का उपयोग करके एक फिक्स्ड नेविगेशन बार बना सकते हैं जो स्क्रॉल पर फिक्स्ड हो जाता है। पोजिशन प्रॉपर्टी सिंटैक्स selector { position: static | relative | absolute | fixed | sticky; } उदाहरण: स्टिकी नेविगेशन बार = sticky) { nav.classLi