This chapter will introduce to you how to set the Table (table) style in CSS? (code example). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
1. Table border
border To specify the CSS table border, use the border attribute.
The following example specifies a black border for the Th and TD elements of a table:
table, th, td { border: 1px solid black; }
Please note that in the above example the table has double borders. This is because the table and th/td elements have separate boundaries.
To display a single border of a table, use the border-collapse property.
2. Collapse border
border-collapse property sets whether the border of the table is folded into a single border or separated:
table { border-collapse:collapse; } table,th, td { border: 1px solid black; }
Three , Table width and height
The Width and height attributes define the width and height of the table.
The following example is a table that sets the width of 100% and the height of the th element to 50 pixels:
table {width:100%;} th{height:50px;}
4. Table text alignment
Text alignment in the table and Vertical alignment property.
The text-align property sets the horizontal alignment, like left, right, or center:
td{text-align:right;}
vertical-align The vertical alignment property sets the vertical alignment, like top, bottom, or center:
td{ height:50px; vertical-align:bottom; }
5. Table filling
padding If you control the borders between spaces in the content of the table, you should use the padding attributes of the td and th elements:
td{padding:15px;}
6. Table color
The following example specifies the color of the border, and the text and background color of the th element:
table, td, th { border:1px solid green; } th { background-color:green; color:white; }
7. Example
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>CSS教程</title> <style> #customers { font-family:"Trebuchet MS", Arial, Helvetica, sans-serif; width:100%; border-collapse:collapse; } #customers td, #customers th { font-size:1em; border:1px solid #98bf21; padding:3px 7px 2px 7px; } #customers th { font-size:1.1em; text-align:left; padding-top:5px; padding-bottom:4px; background-color:#A7C942; color:#ffffff; } #customers tr.alt td { color:#000000; background-color:#EAF2D3; } </style> </head> <body> <table id="customers"> <tr> <th>Company</th> <th>Contact</th> <th>Country</th> </tr> <tr> <td>Alfreds Futterkiste</td> <td>Maria Anders</td> <td>Germany</td> </tr> <tr class="alt"> <td>Berglunds snabbköp</td> <td>Christina Berglund</td> <td>Sweden</td> </tr> <tr> <td>Centro comercial Moctezuma</td> <td>Francisco Chang</td> <td>Mexico</td> </tr> <tr class="alt"> <td>Ernst Handel</td> <td>Roland Mendel</td> <td>Austria</td> </tr> <tr> <td>Island Trading</td> <td>Helen Bennett</td> <td>UK</td> </tr> <tr class="alt"> <td>Königlich Essen</td> <td>Philip Cramer</td> <td>Germany</td> </tr> <tr> <td>Laughing Bacchus Winecellars</td> <td>Yoshi Tannamuri</td> <td>Canada</td> </tr> <tr class="alt"> <td>Magazzini Alimentari Riuniti</td> <td>Giovanni Rovelli</td> <td>Italy</td> </tr> <tr> <td>North/South</td> <td>Simon Crowther</td> <td>UK</td> </tr> <tr class="alt"> <td>Paris spécialités</td> <td>Marie Bertrand</td> <td>France</td> </tr> </table> </body> </html>
Rendering:
The above is the detailed content of How to set the Table style in CSS? (code example). For more information, please follow other related articles on the PHP Chinese website!

A fascinating new site called The Markup just launched. Tagline: Big Tech Is Watching You. We’re Watching Big Tech. Great work from Upstatement. The

I posted about parsing an RSS feed in JavaScript the other day. I also posted about my RSS setup talking about how Feedbin is at the heart of it.

Learn how to create a custom CodePen block with a preview for Sanity Studio, inspired by Chris Coyier’s implementation for Wordpress’ Gutenberg editor.

Line, bar, and pie charts are the bread and butter of dashboards and are the basic components of any data visualization toolkit. Sure, you can use SVG

We are always looking to make the web more accessible. Color contrast is just math, so Sass can help cover edge cases that designers might have missed.

Tartan is a patterned cloth that’s typically associated with Scotland, particularly their fashionable kilts. On tartanify.com, we gathered over 5,000 tartan

Not long ago, I posted about PHP templating in just PHP (which is basically HEREDOC syntax). I'm literally using that technique for some super basic

Have you ever clicked on an image on a webpage that opens up a larger version of the image with navigation to view other photos?


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Atom editor mac version download
The most popular open source editor

SublimeText3 English version
Recommended: Win version, supports code prompts!

Notepad++7.3.1
Easy-to-use and free code editor