हम 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> table, table * { border: thin solid; padding: 5px; font-style: italic; } caption { caption-side: bottom; } td { box-shadow: inset 0 0 6px green; } </style> </head> <body> <table> <caption>Demo caption</caption> <tr> <td>demo</td> </tr> <tr> <td>demo</td> <td></td> </tr> <tr> <td>demo</td> <td>demo</td> <td></td> </tr> </table> </body> </html>आउटपुट
यह निम्नलिखित आउटपुट देता है:

उदाहरण
<!DOCTYPE html> <html> <head> <style> div { display: flex; float: left; } table { border: 3px solid black; } td { border: 3px solid lightgreen; } th { border: 3px solid lightblue; } #t2 { border-collapse: collapse; } </style> </head> <body> <h2>Team Rankings</h2> <div> <table id="t1"> <tr> <th>Team (Test)</th> <th>Rank </th> </tr> <tr> <td>India </td> <td>1 </td> </tr> <tr> <td>Australia</td> <td>2</td> </tr> </table> </div> <div> <table id="t2"> <tr> <th>Team (ODI) </th> <th>Rank </th> </tr> <tr> <td>India </td> <td>1 </td> </tr> <tr> <td>England</td> <td>2</td> </tr> </table> </div> </body> </html>आउटपुट
यह निम्नलिखित आउटपुट देता है:
