Alt-Web Design & Publishing
CSS Zebra Table
Description:
Table rows with alternating background colors or stripes are commonly known as Zebra tables. Tables styled with CSS are more efficient than HTML styled tables. By keeping style separate from content, HTML code bloat is significantly reduced making your pages leaner and faster loading. For another take on CSS styled tables, see 3-Color Columned Table.Example:
| Table Header 1 Subtitle |
Table Header 2 Subtitle |
Table Header 3 Subtitle |
|---|---|---|
| even | some text here | some text here |
| odd | Some text here | Some text here |
| even | Some text here | Some text here |
| odd | Some text here | Some text here |
Method:
CSS2 Code
table {
width: 90%;
border: 2px groove silver;
font: 12px Geneva, Arial, Helvetica, sans-serif;
margin: 0 auto; /**centers table on screen**/
}
caption {
font-size: 2em;
text-align:left;
color: #336699;
font-style:italic;
line-height: 1.8;
font-weight: bold;
}
th {
font:16px bold Arial, Helvetica, sans-serif;
color: maroon;
text-align:center;
background-color: #FFFF99;
}
th,td,tr {border: 1px solid silver; vertical-align:middle; height: 45px; }
.subtitle {font: 14px bold; font-style:italic; color:#000;}
/**Zebra Stripes**/
tr td {background-color: #F1F1F1;}
tr.odd td {background-color: #ECE7CA;}
Earn money from your website with
Lunarpages Affiliate Program.
XHTML Code
<table cellspacing="0" cellpadding="5">
<caption>Zebra Table styled with CSS</caption>
<tr>
<th>Table Header 1<br />
<span class="subtitle">Subtitle</span></th>
<th>Table Header 2 <br />
<span class="subtitle"> Subtitle</span></th>
<th>Table Header 3<br />
<span class="subtitle">Subtitle</span></th>
</tr>
<tr>
<td>even</td>
<td>some text here</td>
<td>some text here</td>
</tr>
<tr class="odd">
<td>odd </td>
<td>Some text here </td>
<td>Some text here </td>
</tr>
<tr>
<td>even </td>
<td>Some text here </td>
<td>Some text here </td>
</tr>
<tr class="odd">
<td>odd </td>
<td>Some text here </td>
<td>Some text here </td>
</tr>
</table>
Demos:
- Photoshop Tutorial - Box with Contoured Edges
- Bringing Image Slices into a CSS Layout
- CSS Disjointed Text Rollovers
- CSS Disjointed Menu Rollover
- Floats & Margins, 3 CSS Boxes
- CSS Menus
- CSS Sprites Demo I
- CSS Sprites Demo II
- CSS2 Captions on Floated Images
- CSS2 Sticky Text
- CSS3 Multi-Backgrounds
- Fixed Background Image
- Liquid Header
- Multi-Scrollbars
CSS Templates:
- Centered, Fixed-Width page with floats
- Centered, Liquid-Width page with floats
- I-Page, Liquid Header & Footer
- 1 Column, Fixed-Width Centered
- Faux Column, Fixed-Width Centered
- Right Column, Fixed-Width Centered
- 3 Column, Fixed-Width Centered
- 3 Column, Liquid Layout
- User Adjustable Page
- Horizontal & Vertical Centered
