हम 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>आउटपुट
यह निम्नलिखित आउटपुट देता है:

उदाहरण
<!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>आउटपुट
यह निम्नलिखित आउटपुट देता है:
