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

CSS से टेबल्स स्टाइल करना


हम CSS का उपयोग करके टेबल्स के लिए स्टाइल्स परिभाषित कर सकते हैं। निम्नलिखित प्रॉपर्टीज़ <table> और उसके एलिमेंट्स को स्टाइल करने के लिए उपयोग की जाती हैं:

  • border

    CSS border प्रॉपर्टी का उपयोग border-width, border-style और border-color को परिभाषित करने के लिए किया जाता है।

  • border-collapse

    यह प्रॉपर्टी स्पेसिफाई करने के लिए उपयोग की जाती है कि <table> एलिमेंट्स में शेयर्ड या सेपरेट बॉर्डर होना चाहिए।

  • caption

    caption-side प्रॉपर्टी का उपयोग टेबल कैप्शन बॉक्स को वर्टिकली पोजिशन करने के लिए किया जाता है।

  • empty-cells

    यह प्रॉपर्टी टेबल के खाली सेल्स के डिस्प्ले को स्पेसिफाई करने के लिए उपयोग की जाती है।

  • table-layout ब्राउज़र द्वारा टेबल की पंक्तियों, कॉलम्स और सेल्स को बिछाने के लिए उपयोग किए जाने वाले एल्गोरिदम को परिभाषित करने के लिए।


उदाहरण

निम्नलिखित उदाहरण टेबल्स की स्टाइलिंग को दर्शाते हैं:

<!DOCTYPE html> <html> <head> <style> body { font-family: 'Bookman Old Style', serif; } th { letter-spacing: 1.9px; } #one { border-right: thick solid blue; } td { text-align: center; } </style> </head> <body> <h2>Employee List</h2> <div> <table> <tr> <th id="one">Employee</th> <th>Department</th> </tr> <tr> <td>John </td> <td>Marketing</td> </tr> <tr> <td>Brad</td> <td>Finance</td> </tr> <tr> <td>Tim </td> <td>IT</td> </tr> <tr> <td>Steve</td> <td>Operations</td> </tr> </table> </div> </body> </html>

आउटपुट

यह निम्नलिखित आउटपुट देता है:

CSS से टेबल्स स्टाइल करना

उदाहरण

<!DOCTYPE html> <html> <head> <style> table { float: left; empty-cells: hide; box-shadow: inset 0 0 4px orange; } tr { box-shadow: inset 0 0 10px greenyellow; } td { font-style: italic; box-shadow: inset 0 0 8px red; } table,td { margin: 6px; padding: 6px; border: 1px solid black; } table </style> </head> <body> <table> <caption>Demo Table</caption> <tr> <th>Head 1</th> <th>Head 2</th> <th>Head 3</th> </tr> <tr> <td>demo</td> <td></td> </tr> <tr> <td></td> <td></td> <td>demo</td> </tr> <tr> <td></td> <td>demo</td> <td></td> </tr> </table> </body> </html>

आउटपुट

यह निम्नलिखित आउटपुट देता है:

CSS से टेबल्स स्टाइल करना

  1. CSS से तुलना टेबल (कॉम्पेरिजन टेबल) कैसे बनाएं? CSS से तुलना टेबल (कॉम्पेरिजन टेबल) कैसे बनाएं?

    कॉम्पेरिजन टेबल में फीचर कॉलम बाएं, प्लान कॉलम दाएं होते हैं। nth-child(even) से वैकल्पिक पंक्ति रंग, पहले कॉलम लेफ्ट-अलाइन, बाकी सेंटर। रिस्पॉन्सिव नहीं है लेकिन साफ डिज़ाइन। उदाहरण <!DOCTYPE html> <html> <head> <meta name=viewport content=width=device-width, initial-scale=

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

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

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

    position: sticky और top: 0 सेट करके, हम HTML टेबल में स्क्रॉल पर एक फिक्स्ड हेडर बना सकते हैं। उदाहरण 1 निम्न उदाहरण हमें इसका कार्यान्वयन करने का अंदाजा देते हैं: <!DOCTYPE html> <html> <head> <style> div {    color: white;    display: flex;