I need to display some data in an HTML page in a three-column, tabular, enumerated environment, like this:
1. elephant animal a large animal that
eats leaves
2. fish animal an animal that
swims in the ocean
3. cactus plant a plant that lives
in dry places
Is there a clean HTML or CSS solution for presenting enumerated tabular environments?
You can make use of the CSS Counter functionality to auto-generate the numbers like shown in the below example:
table{
counter-reset: rows; /* initalize the counter variable */
}
tr{
counter-increment: rows; /* increment the counter every time a tr is encountered */
}
td{ /* just for demo */
vertical-align: top;
width: 100px;
}
td:first-child:before{ /* add the counter value before the first td in every row */
content: counter(rows) ". ";
}
Note:
table
elements itself.counter-reset
whenever a table
tag is encountered to make sure that each row in a new table always starts with 1. If the numbering has to continue into a data in another table, then we can reset the counter at the common parent's level (or if none then at body
).