HTML Table Styling
Use the css property to make your tables designing & Styling.
Use the css property to make your tables designing & Styling.
To style every other table row element, use the :nth-child(odd) selector like this:
<style>
tr:nth-child(odd) {
background-color: lightgray;
}
</style>
<table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<th>Alfreds Futterkiste</th>
<th>Maria Anders</th>
<th>Germany</th>
</tr>
<tr>
<th>Centro comercial Moctezuma</th>
<th>Francisco Chang</th>
<th>Denver</th>
</tr>
<tr>
<th>Moctezuma</th>
<th>Anders</th>
<th>USA</th>
</tr>
</table>
Company | Contact | Country |
---|---|---|
Alfreds Futterkiste | Maria Anders | Germany |
Centro comercial Moctezuma | Francisco Chang | Tokyo |
Moctezuma | Anders | USA |
Set the :nth-child(even) for table data elements like this:
<style>
td:nth-child(even), td:nth-child(even) {
background-color: gray;
}
</style>
Company | Contact | Country | city |
---|---|---|---|
Alfreds Futterkiste | Maria Anders | Germany | Berlin |
Centro comercial Moctezuma | Francisco Chang | Japan | Tokyo |
Moctezuma | Anders | USA | Dearborn |
Use an rgba() color to specify the transparency of the color:
<style>
tr:nth-child(odd) {
background-color: lightgray;
}
td:nth-child(even), td:nth-child(even) {
background-color: gray;
}
</style>
Company | Contact | Country | city |
---|---|---|---|
Alfreds Futterkiste | Maria Anders | Germany | Berlin |
Centro comercial Moctezuma | Francisco Chang | Japan | Tokyo |
Moctezuma | Anders | USA | Dearborn |
Use the :hover selector on tr to highlight table rows on mouse over:
<style>
tr: hover {
background-color : lightgray;
}
</style>
Company | Contact | Country |
---|---|---|
Alfreds Futterkiste | Maria Anders | Germany |
Centro comercial Moctezuma | Francisco Chang | Tokyo |
Moctezuma | Anders | USA |
In this page (written and validated by A. Gawali) you learned about HTML Table styling . What's Next? If you are interested in completing HTML tutorial, your next topic will be learning about: HTML Table colgroup.
Share On: |